note 50896 added to control-structures.switch
| From: | gregory dot mccoy at pleasedontspam dot cafeoui dot net | Date: | Sun, 13 Mar 2005 17:07:48 +0000 |
| Subject: | note 50896 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86359@lists.php.net to get a copy of this message | ||
In the post:
----------------------------------------------------
design at hyperoptix dot com
18-Feb-2004 12:46
Boolean logic does not work inside case statements:
<?php
$x = 18;
$y = 6;
switch ($x) {
case (($y * 4) || (9 * 3)):
echo "Member";
break;
default:
echo "Not a member";
}
?>
echoes "Member".
----------------------------------------------------
there were many responses but all seem to miss the point. You cannot mix apples and oranges. The
"switch($x)" establishes that this "switch" statement will be a Relational
syntax while the "case" qualifier uses a Logical syntax. There must be a match. Either
change "switch($x)" to "switch(true)" or change "case(($y * 4) || (9 *
3)):" to resolve to a value.
The syntax of the original post is like a cop that says, "I want all of your answers to reflect
truth. So, are you eighteen?" The respondent says, " 4 x 4 or 11 + 5". Need I say
more?
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50896
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50896&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50896&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50896&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50896&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50896&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50896&report=yes
Search -- http://master.php.net/manage/user-notes.php