When to use single quote and double quote in PHP

In php most of the time we use single quote('……..') and double quote("…………").
Do we know what is the different between them?

echo 'Hello world!';
echo "Hello world!";

Both will output same. Hello world!
But what is the difference?

Difference is PHP try to parse any varibale inside double quote and replace its value but it does not parse what is inside single quote.
We will clear with following example:

$a=10;
echo 'value of a is $a';
echo "value of a is $a";

First echo will output value of a is $a

Second echo will output value of a is 10;

As we see PHP parse double quote, so single quote is faster than double quote.But  while programing we should not think about such marginal speed.

But I always use single quote unless I do not need both.Our double quote example can be replace with single  quote like this way

echo 'value of a is '.$a;

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *