In PHP, you can use either single or double quotation marks to define a string. There is no difference between the strings defined by these two symbols in normal usage. Today, I wrote a few lines of code as an example of "address assignment," in which both single and double quotation marks are used to define a string ( note the lines fourth and sixth in the following code snippetAfter the execution, something wonderful happened.
$var 1="Chrismao";//assignthevalue "Chirsmao" To$var1
$var 2=&$var 1;//reference$var1via$var2
Echo'Thevalueof$var2is:',$var 2,"
";//$var 2and$var1havethesamevalue "Chrismao"
$var 2='mynameis$var2';//modify$var2,thesametime$var1wasmodified
Echo'Thevalueof$var1is:',$var 1,"
";//thevalueof$var1is "Mynameis$var2"
$var 2="mynewnameis$var1";//modify$var2,thesametime$var1wasmodified
Echo'Thevalueof$var2is:',$var 2,"
";//thevalueof$var1is "Mynewnameismynameis$var2"
Echo'Thevalueof$var1is:',$var 1,"
";//thevalueof$var1is "Mynewnameismynameis$var2"
Is the result of the execution
I wonder if you have seen anything of this result. The same variable name in the code snippet appears in the right string of the assignment statement on line fourth and line sixth of the Code , just one sentence in single quotation marks, the other with double quotes . Before executing, the expected output should be to output the variable name as a string, instead of the output variable value. However, after execution, it is found that the output is different from the previous forecast. the assignment using single quotation marks is to output the variable names in the string as-is, whereas an assignment statement using double quotes replaces the variable name with the actual value output of this variable.
Re-book to explain the string variable chapters, carefully read, impressively found in the book of this phenomenon has long been described: double-quote string The most important thing is that the variable name is replaced by the value of the variable . It's all the trouble of reading!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above introduces the difference between single and double quotes in PHP, including the contents of the content, I hope that the PHP tutorial interested in a friend helpful.