note 50927 added to control-structures.switch
| From: | achaatbitfabrikdootde at osu1 dot php dot net | Date: | Mon, 14 Mar 2005 11:21:53 +0000 |
| Subject: | note 50927 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86393@lists.php.net to get a copy of this message | ||
So instead of writing the code shown below it would have to be like this:
<?php
$x = 18;
$y = 6;
switch ($x) {
case ((($y * 4) || (9 * 3))?$x:false):
echo "Member";
break;
default:
echo "Not a member";
}
?>
So now the case expression contains an if statement in simplified notation which either returns the
value of $x if the expression is true (so the case matches) or false, if the expression was false
(so the case does not match).
Be aware that it only works if $x never actually is "false" because then it would match in
either case. So the "false" in the above code should always be any random value which is
not a possible value for $x.
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50927
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50927&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50927&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50927&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50927&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50927&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50927&report=yes
Search -- http://master.php.net/manage/user-notes.php