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>";

?>
3
  • 9
    You are setting strings and then trying to do multiplication. For example $hours = "1 hour"; -- cannot be multiplied by 60. Commented Feb 11, 2020 at 14:26
  • @Jeremy Harris what changes should I made Commented Feb 11, 2020 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. Commented Feb 11, 2020 at 14:33

1 Answer 1

2

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

Intval() solved my issue

$value = (intval($hours) * 60) + intval($minutes);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.