note 33937 deleted from language.operators.comparison by didou
| From: | didou@php.net | Date: | Fri, 11 Jul 2003 15:04:32 +0000 |
| Subject: | note 33937 deleted from language.operators.comparison by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-51914@lists.php.net to get a copy of this message | ||
Note Submitter: kari_hre@hotmail.com
----
The ternary operator with many conditions has always confused me so I sat down and played with it
for a while. Here are the results.
This:
echo ($var1 == 1) ? ($var2 == 2) ? ($var3 == 3) ? 'a' : 'b' : 'c' :
'd';
works just as:
if ($var1 == 1) {
if ($var2 == 2) {
if ($var3 == 3) {
echo 'a';
} else {
echo 'b';
}
} else {
echo 'c';
}
} else {
echo 'd';
}
Hope this will clear up some confusion!