Is there limitation for switch case: argument's value?
| From: | Keith | Date: | Fri, 21 Aug 2009 03:40:45 +0000 |
| Subject: | Is there limitation for switch case: argument's value? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-297049@lists.php.net to get a copy of this message | ||
Hi,
I encounter a funny limitation here with switch case as below:
The value for $sum is worked as expected for 1 to 8, but not for 0.
When the $sum=0, the first case will be return, which is "sum=8".
Is there any limitation / rules for switch case? Thanks for advice!
Keith
$sum=0;
switch($sum)
{
case ($sum==8):
echo "sum=8";
break;
case ($sum==7 || $sum==6):
echo "sum=7 or 6";
break;
case ($sum==2 || $sum==1):
echo "sum=2 or 1";
break;
case 0:
echo "sum=0";
break;
default:
echo "sum=3/4/5";
break;
}