note 11838 added to language.operators.string.php
| From: | yasuo_ohgaki at hotmail dot com | Date: | Fri, 09 Mar 2001 07:41:11 +0000 |
| Subject: | note 11838 added to language.operators.string.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12098@lists.php.net to get a copy of this message | ||
I think difference between " and ' should be described.
With ", PHP parse contents between " and try to find PHP variables. Therefore,
When $choice has string variable 'apple'.
"your choice is $choice\n" will be
your choice is apple
There will be newline character at the end of string.
Programmer may need to use {} to resolve ambiguity of some variables. For example,
"your choice is {$object->choice}"
When programmer want to get object property. The same thing apply to multi dimensional array
variables.
"your choice is {$array['user']['choice']}"
It applies to <<< here document also.
With ', PHP does NOT parse contents between '. Therefore,
'your choice is $choice\n' will be
your choice is $choice\n
No newline at the end of string when ' is used, since PHP does not parse single quoted strings.
Generally programmers are better to use ' when ' is applicable to avoid parse overhead.
For example, use $array['item'] rather than $array["item"]. Your script will be
executed a bit faster.
http://www.php.net/manual/en/language.operators.string.php