note 19704 added to language.operators
| From: | php dot at dot michrev dot com at php2 dot chek dot com | Date: | Fri, 08 Mar 2002 07:42:11 +0000 |
| Subject: | note 19704 added to language.operators | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27503@lists.php.net to get a copy of this message | ||
If this doesn't work:
($val) ? echo('true') : echo('false');
...you should use this:
if($val) { echo('true'); } else { echo('false'); }
...or, better yet, this:
echo($val ? 'true' : 'false');
...because $val, 'true', and 'false' are all expressions, but echo() is not.
The "expr?expr:expr" operator is used to select between expressions in the middle of a
command. If you need to select between different commands instead, it's probably better to use
if() instead. That's what it's there for.
--
http://www.php.net/manual/en/language.operators.php
http://master.php.net/manage/user-notes.php?action=edit+19704
http://master.php.net/manage/user-notes.php?action=delete+19704
http://master.php.net/manage/user-notes.php?action=reject+19704