note 103202 modified in control-structures.if by danbrown
| From: | danbrown@php.net | Date: | Thu, 31 Mar 2011 14:05:51 +0000 |
| Subject: | note 103202 modified in control-structures.if by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178377@lists.php.net to get a copy of this message | ||
Be careful when you chain inline "if" :
<?php
$x = 1;
$y = 3;
echo ($x==1) ? "One" : ($y == 2) ? "Two" : "None";
?>
Expected result : "One".
Result on screen : "Two".
Pretty disapointing isn't it ?
So, if you want to chain inline "if" you have to use parentesis on each test like below:
<?php
$x=1;
$y=3;
echo ($x==1) ? "One" : ( ($y==2) ? "Two" : "None" );
?>
Result on screen : "One".
Hope it helps !
--was--
Be careful when you chain inline "if" :
$x = 1;
$y = 3;
echo ($x==1) ? "One" : ($y == 2) ? "Two" : "None";
Expected result : "One".
Result on screen : "Two".
Pretty disapointing isn't it ?
So, if you want to chain inline "if" you have to use parentesis on each test like below:
$x=1;
$y=3;
echo ($x==1) ? "One" : ( ($y==2) ? "Two" : "None" );
Result on screen : "One".
Hope it helps !
http://php.net/manual/en/control-structures.if.php