Home >Backend Development >PHP Tutorial >What are the differences between PHP single quotes and double quotes?
This article introduces the difference between single quotes and double quotes in PHP programs, as well as the efficiency issues between the two. Friends in need can refer to it.
Many friends have always thought that single quotes and double quotes in PHP are interoperable. ” ” The fields in double quotes will be interpreted by the compiler and then output as html code. ‘ ‘ The words in the single quotes are not interpreted and are output directly. 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 tomEspecially when using MYSQL statements, the usage of double quotes and single quotes can be confusing to novices. 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 variables are used in the query conditions, for example: $user_name = $_REQUEST['user_name']; //String variable or $user=array ("name"=> $_REQUEST['user_name‘,"age"=>$_REQUEST['age'];//Array variableSQL statement: 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 three parts: 1. “select * from table where user_name = ‘ ” //Fixed SQL statement 2. $user //Variable 3. " ' " Use "." to connect the strings 1, 2, and 3. Let’s test it and see how efficient it is? ! |