note 31748 added to language.operators.comparison
| From: | nick at m-tj dot co dot uk | Date: | Fri, 02 May 2003 10:37:14 +0000 |
| Subject: | note 31748 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47379@lists.php.net to get a copy of this message | ||
The documented example of the Ternary operator lead me to beleive that it could be interchanged with
an If statement and without having programmed in C the note "operates as in C" didn't
help me. So other people don't fall into the same error herre is what I wa trying to do:
(isset($address1)) ? (echo "value=".$address1) : $address1 = null;
which gave me an "Unexpected 'echo'" error when I was expecting the same result
as if I had used:
if (isset($address1)){
echo "value=".$address1;
} else {
$address1 = null;
}
As I understand it, the Ternary operator is used only for assigning values and can't have
functions as the resultant expressions.
--
http://www.php.net/manual/en/language.operators.comparison.php
http://master.php.net/manage/user-notes.php?action=edit+31748
http://master.php.net/manage/user-notes.php?action=delete+31748
http://master.php.net/manage/user-notes.php?action=reject+31748