In fact, I have mentioned the difference and efficiency between single quotes and double quotes in the previous PHP100 video tutorial, but it is still not clear to many friends, I always thought that single quotes and double quotes in PHP were interconnected. I did not study them until one day I found that single quotes and double quotes were incorrect. So today I will talk about their differences, I hope you do not "> <LINKhref =" http://www.php100.com
In fact, I have mentioned the difference and efficiency between single quotes and double quotes in the previous PHP100 video tutorial, but it is still not clear to many friends, I always thought that single quotes and double quotes in PHP were interconnected. I did not study them until one day I found that single quotes and double quotes were incorrect. So let's talk about their differences today. I hope you will not be confused.
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 tom
Echo '$ ABC' // The result is: $ abc
Echo "$ abc" // The result is: my name is tom
Especially when using MYSQL statements, double quotation marks and single quotation marks are confusing for beginners. here, we will give an example to describe them.
Assume that constants are used in the query conditions, for example:
Select * from abc_table where user_name = 'abc ';
The SQL statement can be written as follows:
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
The SQL statement can be written as follows:
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 :"'"
Use "." to connect 1, 2, 3 strings.