note 54617 added to language.variables
| From: | MikeFotes at osu1 dot php dot net | Date: | Sat, 09 Jul 2005 18:46:30 +0000 |
| Subject: | note 54617 added to language.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91719@lists.php.net to get a copy of this message | ||
In conditional assignment of variables, be careful because the strings may take over the value of
the variable if you do something like this:
<?php
$condition = true;
// Outputs " <-- That should say test"
echo "test" . ($condition) ? " <-- That should say test" : "";
?>
You will need to enclose the conditional statement and assignments in parenthesis to have it work
correctly:
<?php
$condition = true;
// Outputs "test <-- That should say test"
echo "test" . (($condition) ? " <-- That should say test " : "");
?>
----
Manual Page -- http://www.php.net/manual/en/language.variables.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54617
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54617&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54617&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54617&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54617&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54617&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54617&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54617&report=yes
Search -- http://master.php.net/manage/user-notes.php