What are the differences between single and double quotation marks in PHP?

Source: Internet
Author: User
What are the differences between single and double quotation marks in PHP?
This article introduces the difference between single quotation marks and double quotation marks in php programs, as well as the efficiency problem between the two. if you need it, refer to it.

Many friends always think that single quotes and double quotes in PHP are interconnected.

The fields in double quotation marks are interpreted by the compiler and then output as html code.

''Is output directly without being interpreted in single quotes.

It can be seen from the literal meaning that single quotes are faster than double quotes.

For example:

$ Abc = 'My name is tome '; echo $ abc // The result is: my name is tomecho' $ ABC' // The result is: $ abcecho "$ abc" // The result is: my name is tom.

Especially when using MYSQL statements, the usage of double quotation marks and single quotation marks is confusing for beginners.

Assume that constants are used in the query conditions, for example:

Select * from abc_table where user_name = 'abc ';

SQL statement:

SQLstr = "select * from abc_table where user _ name = 'abc '";

Assume that the query conditions use variables, for example:

$ User_name = $ _ REQUEST ['User _ name']; // string variable or $ user = array ("name" => $ _ REQUEST ['User _ name ', "age" = >$ _ REQUEST ['age']; // array variable

SQL statement:

SQLstr = "select * from abc_table where user_name = '". $ user_name. "'"; SQLstr = "select * from abc_table where user_name = '". $ user ["name"]. ';

Comparison:

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 divided into the following three parts: 1. "select * from table where user_name = '" // fixed SQL statement 2, $ user // variable 3, "'" 1, 2, use "between three strings "..

Let's test the efficiency ?!

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.