note 38046 added to control-structures.alternative-syntax
| From: | ssttoo at hotmail dot com | Date: | Fri, 05 Dec 2003 22:20:28 +0000 |
| Subject: | note 38046 added to control-structures.alternative-syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61466@lists.php.net to get a copy of this message | ||
Nested ternary operators can be used, although not a "good programming practice", as it
does not promote readability and is prone to errors.
<?php
$one = true;
$two = true;
$result = ($one) ? "one" : (($two) ? "two" : "none"); // $result is
"one"
$result = ($one) ? "one" : ($two) ? "two" : "none"; // $result is
"two"
?>
----
Manual Page -- http://www.php.net/manual/en/control-structures.alternative-syntax.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38046
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38046&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38046&report=yes
Search -- http://master.php.net/manage/user-notes.php