note 15286 deleted from language.operators.comparison by sniper

From: Date: Mon, 13 Oct 2003 00:16:12 +0000
Subject: note 15286 deleted from language.operators.comparison by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58428@lists.php.net to get a copy of this message
Note Submitter: josh@3io.com ---- 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)

« previous php.notes (#58428) next »