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?

青灯夜游
青灯夜游Original
2019-10-17 14:48:526234browse

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

The operating environment of this tutorial: windows7 system, PHP8 version, DELL G3 computer

The difference between single quotes and double quotes

Single quotes and double quotes in PHP are often interchangeable, but there are also differences:

1. Single quotes

The content will not be interpreted (\n will not be output as a newline, but will be output directly), that is, the content will be consistent with the input content, for example:

<?php
$a = 123;
echo &#39;a is $a&#39;;

The output content is:

a is $a

2. Double quotes

The content in double quotes will be interpreted, that is, the variables in the content will be parsed, for example:

<?php
$a = 123;
echo "a is $a";

The output result is:

a is 123

3. Note

1) Insert single quotes between double quotes. If there are variables in single quotes, variables will be interpreted

2), because the content of double quotes will be interpreted, the efficiency of double quotes will be lower than that of single quotes, so we can

try our best to Use single quotes

If you include variables that need to be parsed, use double quotes

For more PHP related knowledge, please visit php Chinese website !

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!

Statement:
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