In PHP, what is the difference between single and double quoted strings?
P粉604507867
2023-08-18 11:45:01
<p>I'm a little confused why in PHP some strings in the code use single quotes and some use double quotes. </p>
<p>I only know that in .NET or C, if you use single quotes, that means it's a character, not a string. </p>
The content in double quotes will be parsed, but the content in single quotes will not be parsed:
PHP string can be specified not only in two ways, but also in four ways.
\', and to display a backslash, escape it with another backslash\\Escape (so, yes, even single-quoted strings will be parsed).$typeand you want toecho "The $types are". This will look for the variable$types. To solve this problem, useecho "The {$type}s are". Check out String Parsing to learn how to use array variables etc.<<<. After this operator, provide an identifier, followed by a newline character. Then the string itself, and the same identifier is used again to close the reference. In this syntax, you don't need to escape quotes.<<<sequence as heredoc, but the following identifier is enclosed in single quotes, such as<<<'EOT'. No parsing is done in Nowdoc.Notice: Single quotes within single quotes and double quotes within double quotes must be escaped:
speed:
no difference. Please read a
Trusted Article from a core PHP developer. When it comes to testing, we should never take it for granted. It is important to understand that writing trustworthy tests and interpreting their results requires a lot of knowledge and experience. This means that most tests are fake. For example, in code like this
for($i=0;$i<100000;$i++) { 'string'; }The quoted string is parsedonly once , along with the entire script, and then converted to opcodes. Then do it a million times. Therefore, what it measures is not parsing. This is just the tip of the iceberg. With nanobenchmarks like this, it's nearly impossible to create a trustworthy test that won't be marred by some interfering side effects.