note 104212 deleted from control-structures.switch by danbrown

From: Date: Wed, 01 Jun 2011 18:54:31 +0000
Subject: note 104212 deleted from control-structures.switch by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180171@lists.php.net to get a copy of this message
Note Submitter: bm13kk at gmail dot com ---- I've read 2 comments (http://ua2.php.net/manual/en/control-structures.switch.php#93342, http://ua2.php.net/manual/en/control-structures.switch.php#88643) with the code like: <?php switch ($foo) { case ($foo<1): echo 'a'; break; case ($foo>1): echo 'b'; break; case ($foo>10): echo 'c'; break; } ?> But it is wrong. It prints 'b' because code above is equivalent <?php if ($foo == ($foo<1)) {echo 'a';} if ($foo == ($foo>1)) {echo 'b';} if ($foo == ($foo>10)) {echo 'c';} ?> If you realy dislike elseif, use this style <?php switch (TRUE) { case ($foo<1): break; case ($foo>1): break; case ($foo>10): break; } ?>

« previous php.notes (#180171) next »