This bit of code:
$hour = 2.2;
if (floor($hour) > 1) {
$str = $str . floor($hour) . " hours";
}
else if (floor($hour) === 1) {
$str = $str . floor($hour) . " hour";
}
echo $str;
Will output: 2 hours
However, this bit:
$hour = 1.2;
if (floor($hour) > 1) {
$str = $str . floor($hour) . " hours, ";
}
else if (floor($hour) === 1) {
$str = $str . floor($hour) . " hour ";
}
echo $str;
Will not output 1 hour, because the condition for the else if does not match for some reason. Why is that?
Floor returns a float, you’re testing for an integer.
http://php.net/manual/en/function.floor.php
Edit for clarity: