note 38046 deleted from control-structures.alternative-syntax by bobby
| From: | bobby@php.net | Date: | Mon, 25 Sep 2006 15:51:00 +0000 |
| Subject: | note 38046 deleted from control-structures.alternative-syntax by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117632@lists.php.net to get a copy of this message | ||
Note Submitter: ssttoo at hotmail dot com
----
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"
?>