When to use single quotes and double quotes in PHP - difference

What is difference between single quotes and double quotes in PHP. When should be each type of them used ?
02 Dec 2020 at 08:41 AM
0pnshow more

It may look there is no difference between single qutoes and double quotes when you use them for example to display some simple text:

echo "Abcde"; // will return Abcde
echo 'Abcde'; // will return Abcde

But you can find differences when you are using quotes for example in relation to some variables:

$value = 123;
echo "Abcde $value"; // will return Abcde 123
echo 'Abcde $value'; // will return Abcde $value

In some cases the usage of single or double quotes may be faster. Using single quotes for simple displaying of text can be faster than using double quotes:

echo 'Abcde'; // can be faster
echo "Abcde";

But using of double quotes in relation to some variable may be faster:

$value = 123;
echo "Abcde $value"; // can be faster
echo 'Abcde ' . $value;

20 Dec 2020 at 12:30 PM
0pnshow more
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2021 AnswerTabsTermsContact us