note 60433 added to function.echo
| From: | thedotonlydotstormatgmaildotcom at osu1 dot php dot net | Date: | Fri, 06 Jan 2006 20:38:36 +0000 |
| Subject: | note 60433 added to function.echo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101319@lists.php.net to get a copy of this message | ||
In reply to lorenpr at gmail dot com:
"I hope this ternary thing isn't overkill. Last thing - I would just like to make you
aware of the side effect when you do this statement,
<?php
echo $some_var ? print 'true': print 'false';
?>
The result would be either 'true1' or 'false1', depending on whether $some_var
is true or false respectively. This happens because of what I mentioned earlier. Figure it
out."
The reason it prints the 1 because whether the variable is true or false, in this case, print will
always return 1 (true)
Meaning this is the same thing:
<?php
echo print($some_var ? 'true' : 'false');
?>
print($some_var ? 'true' : 'false') = 1
So you echo 1, after the print takes place.
----
Manual Page -- http://www.php.net/manual/en/function.echo.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60433
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60433&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60433&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60433&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60433&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60433&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60433&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60433&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60433&report=yes
Search -- http://master.php.net/manage/user-notes.php