What is the difference between single quotes and double quotes in php ?

In this article, We’ll see what is the difference between single quotes ' and double quotes " in php?

single quotes: It is the simplest way to specify a string is to enclose it in single quotes (‘). single quotes is generally faster than double quotes and everything quoted inside treated as plain string and php will not evaluate the string enclosed by single quotes so that’s reason it is fast.




	$user_name = "John Doe";
	echo 'Hello $user_name'; // Output Hello $user_name
	echo 'This is \'test\' string'; // Output This is test string

double quotes: The most important feature of double-quoted strings is the fact that variables in the strings will be evaluated. we can use curly braces to isolate the user name of the variable you want evaluated.

	$user_name = "John Doe";
	echo "Hello {$user_name}"; // Output Hello John Doe

Performance: The single-quoted strings are faster at runtime because they do not need to be parsed. when we use double quotes "" php has to parse to check if there is any variables in there.

That’s it!. Please share your thoughts or suggestions in the comments below.

Posted in PHP

Leave a Reply

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