The difference between single quotes and double quotes in php is: 1. Variables inside double quotes will be parsed, but not inside single quotes; 2. Variables and special characters in double quotes will be escaped. Content within single quotes will not be escaped.
In PHP, the definition of a string can use English single quotes ' ' or English double quotes " ".
(Recommended tutorial: php graphic tutorial)
Generally, the two are common, but the variables inside the double quotes will be parsed, but the single quotes will not be parsed.
PHP allows us to directly include string variables in double quotes, and the content in single quote strings is always considered to be ordinary characters, so the content in single quotes will not be escaped, which is more efficient.
(Video tutorial recommendation: php video tutorial)
For example:
$str='hello'; echo "str is $str"; //运行结果: str is hello echo 'str is $str'; //运行结果: str is $str
In php, variables ($var) in double quotes and special Characters (such as \r\n) will be escaped, but the content in single quotes will not be escaped (so it is more efficient).
The above is the detailed content of What is the difference between single quotes and double quotes in php. For more information, please follow other related articles on the PHP Chinese website!