Possible Duplicate:
Difference between single quote and double quote string in php
I’m a newbie to PHP and I’m getting a little confused about how to specify strings.
There seem to be 4 ways to specify strings
- Single quoted strings
- Double quote strings
- Heredoc
- Nowdoc (since PHP 5.3.0)
I was wondering why there are so many types of specifications and what is the best way to specify a string?
Because again in this article it says single and double quotes are equally fast but there are others which disagree.
Why even have single and double quotes? Does it add speed, accuracy is any one better under certain conditions?
Single-quoted strings pay attention to less escape sequences than double-quoted strings. Compare:
with:
The other key difference is that double-quoted strings interpolate variables. Single-quoted strings don’t.
As for heredoc and nowdoc, they’re just ways to specify long strings (that may contain quotes – and if they do, you don’t have to escape them) in a bit of a nicer way. Why are there two? Well, heredoc is to double-quoted strings as nowdoc is to single-quoted strings.
(All this information and more is available in the PHP documentation, by the way.)
So, there are a lot of different types of string literal because there are a lot of different uses for string literals.