note 84151 deleted from control-structures.switch by mgf
| From: | mgf@php.net | Date: | Mon, 07 Jul 2008 11:35:46 +0000 |
| Subject: | note 84151 deleted from control-structures.switch by mgf | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141225@lists.php.net to get a copy of this message | ||
Note Submitter: mmxg at shaw dot ca
Reason: bad code
----
I just also found that you can add extra conditional statements inside of a case, which is what I
was hoping to find out but nobody seems to have yet mentioned.
<?php
$int=5;
switch($int)
{
case 1:
echo "this is 1";
break;
case 2:
echo "this is 2";
break;
case ($int > 4):
echo "this is greater than 4";
break;
}
?>
You would probably expect the conditional ($int > 4) to return TRUE, and then compare (integer) 5
to (integer) 1, but instead it does the (5 > 4) comparison and it outputs "this is greater
than 4". Just in case you need to specify a specific range of other values instead of just
default.
I hope that helps