0

I am generating drop down list to show 15 minutes duration till 6 hrs it will generate like 15 minutes ,30 minutes,45 minutes but I am getting error non numeric value encountered so I followed below links but It didn't solved my issue

links Refer:

date() method, "A non well formed numeric value encountered" does not want to format a date passed in $_POST

A non well formed numeric value encountered - Error in PHP

<?php 

echo "<select>";

for($i = 0; $i <= 6; $i++){
    for ($j = 0; $j <= 45; $j +=15){
        if ($i === 0 && $j === 0){
            //do nothing
        }
        else{
            //get string for hours
            switch($i){
                case 0:
                    $hours = "";
                    break;
                case 1:
                    $hours = "1 hour";
                    break;
                default:
                    $hours = $i . " hours";
                    break;
            }

            //get string for minutes
            switch($j){
                case 0:
                    $minutes = "";
                    break;
                default:
                    $minutes = $j . " minutes";
                    break;
            }

            $value = ($hours * 60) + $minutes;



            //output
            echo "<option value='" . $value . "'>" . $hours . " " . $minutes . "</option>";
        }
    }
}

echo "</select>";

?>
msp
  • 127
  • 1
  • 12
  • 9
    You are setting strings and then trying to do multiplication. For example `$hours = "1 hour";` -- cannot be multiplied by 60. – Jeremy Harris Feb 11 '20 at 14:26
  • @Jeremy Harris what changes should I made – msp Feb 11 '20 at 14:31
  • Don't try to multiply "1 hour" by 60. Change your code to only handle numbers in your loops, and then worry about how to display it AFTER you calculate. – Jeremy Harris Feb 11 '20 at 14:33

1 Answers1

2

It was mistake which I did in code as suggested by @Jeremy Harris

Intval() solved my issue

$value = (intval($hours) * 60) + intval($minutes);
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
msp
  • 127
  • 1
  • 12