note 33937 added to language.operators.comparison
| From: | kari_hre at hotmail dot com | Date: | Fri, 11 Jul 2003 14:54:50 +0000 |
| Subject: | note 33937 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51912@lists.php.net to get a copy of this message | ||
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!
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33937
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33937&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33937&report=yes