today we directly through a few practical small cases to explain the difference, we observe carefully!
//double quotation mark knowledge explanation
//This is a mistake because it will treat hello as a double-quote character, and world will be a character you don't know.
$str 1 = "Hello" World "".
';
//correct notation: the world with double quotes should be added with the escape character \ So there will be no boundary ambiguity
$str 1 = "Hello \" world\ "".
';
Echo $str 1;
$str 2 = "Hello \n\r\t world".
'; //\n\r: NewLine carriage return, double quotation marks can be parsed
Echo $str 2;
$str 3 = "Hello $str 1". '
'; //At this point the system will parse the $STR1 into a variable, it will call $STR1
Echo $str 3;
$str 4 = "Hello \ $str 1"; After the //is compliant with the escape character, the system will treat $str1 as a normal string and no longer a variable
Echo $STR 4;
//Single quotation mark knowledge explanation
$str 1 = ' Hello \n\r\t world '. '
'; //Single quotation mark cannot resolve recognition \n\r\t, it will be output directly as normal character
echo $str 1;
$str 2 = ' Hello $str 1 '; //single quotation marks can not resolve the identification $ symbol, will be directly $str1 when the normal character output
echo $str 2;
single-double quotation mark mixed explanation, get 3 conclusion:
1. Single quotes cannot be escaped too much, only \ \ ', and double quotes can be escaped \ \ \ \ \ \ \ \t
2. Single quotation marks cannot resolve the $ variable character, whereas double quotes can be
3. Because single quotes do not have to be considered in many cases, single quotes are faster than double quotes!
I believe that through tonight's analysis, everyone later on in PHP single double quotes, there will be no doubt about it! If everyone thinks it's good, feel free to
A little reward , thank you!
The above describes the PHP single double quotation mark relationship and differences, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.