I’m a little confused why I see some code in PHP with string placed in single quotes and sometimes in double quotes.
I just know in .NET, or the C language, if it is in a single quote, that means it is a character, not a string.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP strings can be specified not just in two ways, but in four ways.
\', and to display a back slash, you can escape it with another backslash\\(So yes, even single quoted strings are parsed).$typeand you want toecho "The $types are". That will look for the variable$types. To get around this useecho "The {$type}s are". Take a look at string parsing to see how to use array variables and such.<<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. You don’t need to escape quotes in this syntax.<<<sequence used for heredocs, but the identifier which follows is enclosed in single quotes, e.g.<<<'EOT'. No parsing is done in nowdoc.Notes:
Single quotes inside of single quotes and double quotes inside of double quotes must be escaped:
Speed:
There is no difference.
Please read a credible article on the matter from one of PHP core developers. Speaking of tests, one should never take them for granted. It must be understood that writing a credible test and, especially, interpreting its results requires a lot of knowledge and experience. Which means that most tests out there are just bogus. For example, in a code like this
The quoted string gets parsed only once, along with entire script, and then gets translated into opcode. Which is then gets executed a million times. So it measures anything but parsing. And that’s only a tip of the iceberg. For a nanobenchmark like this, it’s practically impossible to create a credible test that wouldn’t be spoiled by some interfering side effect.