note 11838 modified in language.operators.string by jmcastagnetto

From: Date: Thu, 16 Jan 2003 03:38:30 +0000
Subject: note 11838 modified in language.operators.string by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-42203@lists.php.net to get a copy of this message
[Editor's note: This is a good rehash of what is already explained in detail in the manual chapter for string types, not only the different ways of defining a string are explained there, but also the how variables are parsed and expanded, and when. You as a reader, should go and read that section carefully. This information has been in the manual since about December 1999.] 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. --was-- 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

« previous php.notes (#42203) next »