Another talk about PHP single and double quote differences

Source: Internet
Author: User

In fact, in the previous PHP100 video tutorial, I have said that the difference between single and double quotation marks and efficiency problems, but still many friends understand is not very clear, always thought that the single quotation marks and double quotation marks in PHP is interoperable, until one day, found that single and double quotation marks in the wrong time to study. So let's talk about their differences today and hope that we don't get confused about it.
The fields inside the double quotation mark are interpreted by the compiler and then output as HTML code.
"The single quotation mark does not explain, the direct output."
It can be seen literally that single quotes are faster than double quotes.
For example: Shangri-La Casino
$ABC = ' My name is tome ';
echo $ABC//Result: My name is Tom
Echo ' $ABC '//Result: $ABC
echo "$ABC"//Result: My name is Tom
Especially when using MySQL statements, the use of double and single quotes is confusing for novices, here, for example, to illustrate.
Suppose a constant is used in a query condition, for example:
SELECT * from abc_table where user_name= ' abc ';
SQL statements can be written as:
SQLSTR = "SELECT * from abc_table where user _name= ' abc '";
Suppose a variable is used in a query condition, for example:
$user _name = $_request[' user_name '); String variables
Or
$user =array ("name" = $_request[' user_name ', ' age ' =>$_request[' age '];//array variable
SQL statements can be written as:
SQLSTR = "SELECT * from abc_table where user_name = '". $user _name. " ‘ ";
SQLSTR = "SELECT * from abc_table where user_name = '". $user [' name ']. " ‘ ";
Compare:
Sqlstr= "SELECT * from abc_table where user_name = ' abc '";
Sqlstr= "SELECT * from abc_table where user_name = '". $user _name. " ‘ ";
Sqlstr= "SELECT * from abc_table where user_name = '". $user [' name ']. " ‘ ";
Sqlstr can be decomposed into the following 3 parts:
1: "SELECT * FROM table where user_name = '"//fixed SQL statement
2: $user//variable
3: "'"
The "." Connection between the half-and-part strings

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.