PHP nested ternary operators behave differently.
This syntax passes all the following tests.
Based on http://deadlytechnology.com/web-development-tips/php-ternary-syntax/
$myvar = ($x == $y)
?(($x == $z)?'both':'foo')
:(($x == $z)?'bar':'none');
.
See: http://au.php.net/ternary
Example #3 "Non-obvious Ternary Behaviour" explains why the following does not work in PHP.
$x = 1;
$y = 2;
$z = 3;
$myvar = ($x == $y)
? "foo"
: ($x == $z)
? "bar"
: "none";
$myvar == 'none'; // Good
$x = 1;
$y = 2;
$z = 1;
$myvar = ($x == $y) ? "foo" : ($x == $z) ? "bar" : "none";
$myvar == 'bar'; // Good
$x = 1;
$y = 1;
$z = 3;
$myvar = ($x == $y) ? "foo" : ($x == $z) ? "bar" : "none";
$myvar == 'bar'; // Bad!
$x = 1;
$y = 1;
$z = 1;
$myvar = ($x == $y) ? "foo" : ($x == $z) ? "bar" : "none";
$myvar == 'bar'; // Bad!