The difference between single and double quotation marks in PHP

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.