note 88770 deleted from control-structures.switch by danbrown
| From: | danbrown@php.net | Date: | Fri, 06 Feb 2009 22:54:13 +0000 |
| Subject: | note 88770 deleted from control-structures.switch by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150322@lists.php.net to get a copy of this message | ||
Note Submitter: admin at edogs dot ru
----
I must confess, that "sedativchunk at gmail dot com" in his comment at 02-Feb-2009 a bit
wrong.
Let's take simple example
$a=0;
switch($a) {
case ($a < 100):echo 1;break;
case ($a > 100):echo 2;break;
}
this will output 2 (TWO!). Seems strange? Nope at all.
Switch is NOT simular to
if($a<100) echo 1; elseif($a>100) echo 2;
It's simular to
if($a==($a<100)) echo 1; else ($a==($a>100)) echo 2;
becase it's COMPRASSION to VALUE in switch.
switch($bac) case $b*10 will compare $bac to $b*10
if you wanna use switch such way, use
switch(true) {
case ($a < 100):echo 1;break;
case ($a > 100):echo 2;break;
}
because (true==($a<100)) is simular to $a<100
/edogs