note 11838 deleted from language.operators.string by didou

From: Date: Thu, 23 Oct 2003 16:27:42 +0000
Subject: note 11838 deleted from language.operators.string by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59177@lists.php.net to get a copy of this message
Note Submitter: yasuo_ohgaki@hotmail.com ---- [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.

« previous php.notes (#59177) next »