note 41950 added to language.operators.string
| From: | anders dot benke at telia dot com | Date: | Tue, 27 Apr 2004 13:53:35 +0000 |
| Subject: | note 41950 added to language.operators.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68886@lists.php.net to get a copy of this message | ||
A word of caution - the dot operator has the same precedence as + and -, which can yield unexpected
results.
Example:
<php
$var = 3;
echo "Result: " . $var + 3;
?>
The above will print out "3" instead of "Result: 6", since first the string
"Result3" is created and this is then added to 3 yielding 3, non-empty non-numeric strings
being converted to 0.
To print "Result: 6", use parantheses to alter precedence:
<php
$var = 3;
echo "Result: " . ($var + 3);
?>
----
Manual Page -- http://www.php.net/manual/en/language.operators.string.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41950
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41950&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41950&report=yes
Search -- http://master.php.net/manage/user-notes.php