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 ?
0
give a positive ratinggive a negative rating
02 Dec 2020 at 08:41 AM
Hi,

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;

0
give a positive ratinggive a negative rating
20 Dec 2020 at 12:30 PM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us