note 84151 added to control-structures.switch
| From: | mmxgatshawdotca at osu1 dot php dot net | Date: | Tue, 01 Jul 2008 08:41:39 +0000 |
| Subject: | note 84151 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141027@lists.php.net to get a copy of this message | ||
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
----
Server IP: 216.235.15.211
Probable Submitter: 24.108.81.100
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/84151
Del: integrated -- https://master.php.net/note/delete/84151/integrated
Del: useless -- https://master.php.net/note/delete/84151/useless
Del: bad code -- https://master.php.net/note/delete/84151/bad+code
Del: spam -- https://master.php.net/note/delete/84151/spam
Del: non-english -- https://master.php.net/note/delete/84151/non-english
Del: in docs -- https://master.php.net/note/delete/84151/in+docs
Del: other reasons-- https://master.php.net/note/delete/84151
Reject -- https://master.php.net/note/reject/84151
Search -- https://master.php.net/manage/user-notes.php