note 15286 added to language.operators.comparison
| From: | josh at 3io dot com | Date: | Tue, 04 Sep 2001 18:23:41 +0000 |
| Subject: | note 15286 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17613@lists.php.net to get a copy of this message | ||
here is a valid example of how parens affect use of the ternary operator in a chain. With parens
the first true value is returned, otherwise the LAST true value is returned.
$a = 5.5;
<?
$b = ($a < 0 ? '0'
: ($a < 1 ? '1'
: ($a < 2 ? '2'
: ($a < 3 ? '3'
: ($a < 4 ? '4'
: ($a < 5 ? '5'
: ($a < 6 ? '6'
: ($a < 7 ? '7'
: ($a < 8 ? '8'
: 'foo' )))))))));
?>
($b == '6')
without parens:
<?
$b = $a < 0 ? '0'
: $a < 1 ? '1'
: $a < 2 ? '2'
: $a < 3 ? '3'
: $a < 4 ? '4'
: $a < 5 ? '5'
: $a < 6 ? '6'
: $a < 7 ? '7'
: $a < 8 ? '8'
: $a == 'cheesemonkey' ? 'eek'
: $a < 10 ? '10'
: 'foo' ;
?>
($b == 10)
http://www.php.net/manual/en/language.operators.comparison.php