Hi, I'm struggling with this particular use of a switch statement.
I'm trying to use a case that is a range of numbers.
Seems to work alright, until you change the variable $number to 0 (ZERO).
<?php
$number=3;
switch ($number) {
case $number >=0 && $number <=10:
print "The number is between 0 and 10";
break;
case $number >=11 && $number <=20:
print "The number is between 11 and 20";
break;
default:
print "Your number is not between 0 and 20";
}
?>
Or many other forms I've tried.
case >=0 && <=10:
case ">=0 && <=10":
case ">=0" && "<=10":
case ($number >=0 && $number <=10):
case ($number >="0" && $number <="10"):
I guess the longer question is what is the correct way to write this idea so that it works?
I've looked at it so long I'm probably missing something real simple (like how to deal with zero as an integer), but I can't see it and any help would be appreciated greatly.
Many Thanks,
love the book!