Difference between single quotes and double quotes in PHP

Source: Internet
Author: User
: This article mainly introduces the difference between single quotes and double quotes in PHP. if you are interested in the PHP Tutorial, please refer to it. In PHP, you can use single or double quotation marks to define a string. In normal use, there is no difference between the two symbol-defined strings. Today, I wrote several lines of code as an example to illustrate "assignment by address assignment, in this code, both single quotes and double quotes are used to define strings (note the fourth and sixth lines in the code segment below). after the execution, a wonderful thing happened.

$ Var1 = "ChrisMao"; // Assignthevalue "ChirsMao" to $ var1
$ Var2 = & $ var1; // Reference $ var1via $ var2
Echo'Thevalueof $ var2is:', $ Var2 ,"
"; // $ Var2and $ var1havethesamevalue" ChrisMao"
$ Var2 = 'mynameis $ var2'; // Modify $ var2, thesametime $ var1wasmodified
Echo'Thevalueof $ var1is:', $ Var1 ,"
"; // Thevalueof $ var1is" mynameis $ var2"
$ Var2 = "myNewnameis $ var1"; // Modify $ var2, thesametime $ var1wasmodified
Echo'Thevalueof $ var2is:', $ Var2 ,"
"; // Thevalueof $ var1is" myNewnameismynameis $ var2"
Echo'Thevalueof $ var1is:', $ Var1 ,"
"; // Thevalueof $ var1is" myNewnameismynameis $ var2"

Is the execution result

I wonder if you have found anything in this result. The variable name is the same as the variable name in the code snippet in the right string of the value assignment statement in the fourth and sixth lines of the code, but it is a single quotation mark, and the other is a double quotation mark. Before execution, the expected output should be to output the variable name as the string, rather than the variable value. However, after execution, the output is different from the previous expectation. The variable name in the string is output using the single quotation mark assignment, while the variable name is replaced by the actual value output for the variable using the double quotation mark assignment statement.

I will go back to the chapter about variable strings and read them carefully. I found that this phenomenon has been described in the book: The most important thing about double quotation marks is that the variable name will be replaced by the variable value. It's all about reading books!

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the difference between single quotes and double quotes in PHP, including content, and hope to be helpful to friends who are interested in PHP tutorials.

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.