Home > Backend Development > PHP Problem > What is the difference between single quotes and double quotes in php?

What is the difference between single quotes and double quotes in php?

王林
Release: 2023-02-23 17:24:01
forward
6373 people have browsed it

What is the difference between single quotes and double quotes in php?

In php, the definition of a string can use either single quotes or double quotes.

Generally, the two are common, but double quotes will parse variables, but single quotes will not.

php allows us to include string variables directly in double quotes.

The content in single quotes will be considered as ordinary characters, so the content in single quotes will not be parsed, and the efficiency is higher.

For example:

$str='hello';
echo "str is $str"; //运行结果: str is hello
echo 'str is $str'; //运行结果: str is $str
Copy after login

In PHP, variables and special characters in double quotes will be escaped, but in single quotes they will be treated as ordinary characters and will not be escaped, so , single quotes are more efficient than double quotes.

For more details, please visit the PHP Chinese website: PHP Video Tutorial

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template