What is the difference between ' and _ in PHP_ - Stack Overflow
What is the difference between ' and _ in PHP_ - Stack Overflow
stackoverflow.com/questions/1402566/what-is-the-difference-between-and-in-php
AI feature from
Try it now
30
Possible Duplicate:
PHP: different quotes?
Simple question:
What is the difference between ' and " in php? When should I use either?
phpsyntax
The larger a repository of stuff gets the harder it is to actually find something. The
absolute worst example I've seen so far is Mozilla's bug tracker. Stack Overflow
gets close with some topics where you can't really be sure of the terms used and
even less sure of the search terms to use to find it. – Joey Sep 9, 2009 at 23:04
Add a comment
6 Answers
25
Basically, single-quoted strings are plain text with virtually no special case whereas
double-quoted strings have variable interpolation (e.g. echo "Hello $username";) as
well as escaped sequences such as "\n" (newline.)
Josh Davis
23
single quoted
double quoted
heredoc
variables and escape sequences for special characters will not be expanded
For instance :
Will output :
With double-quotes :
The most important feature of double-quoted strings is the fact that variable names
will be expanded.
For instance :
$a = 10;
echo "a is $a";
Will output :
a is 10
Heredoc text behaves just like a double-quoted string, without the double quotes.
This means that quotes in a heredoc do not need to be escaped,
For instance :
$a = 10;
$b = 'hello';
$str = <<<END_STR
a is $a
and "b" is $b.
END_STR;
echo $str;
a is 10
and "b" is hello.
edited Aug 31, 2012 at 11:45
Abhishek Bhatia
71699 silver badges2626 bronze badges
The difference is, strings between double quotes (") are parsed for variable and escape
sequence substitution. Strings in single quotes (') aren't.
$count = 3;
echo "The count is:\t$count";
Also, the characters that need to be escaped. If you have a string like:
you would probably use single quotes, to avoid having to escape the quotes in the string
and vice-versa.
Brenton Alker
8,97233 gold badges3636 silver badges3737 bronze badges
Add a comment
0
In one word: when you would like to all your special chars (like \n) and varables (like
$number) be noticed and process.
IProblemFactory
9,66988 gold badges5151 silver badges6666 bronze badges
Add a comment