+

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

Single quoted strings:This is the simplest way to define a string. You can use it whenever you want the string to be exactly as it is written. All escape sequences such as / ror / nwill be output as specified instead of having any special meaning. A single quote is usually faster in some cases. A special case is that if you want to display a literal single quote, escape it with a backslash (/),and if you want to display a backslash, you can escape it with another backslash (//) .The program below illustrates lineswithin single quotes:
Program 1:  
// Simple string echo `I am a geek. ` ; echo "" ;  
// use a backslash to display a line with an apostrophe echo `It`ll be interesting to know about the string. ` ; echo "" ;  
// escape backslash in line echo `A is named as backslash. ` ; echo "" ;  
// Variable will not be evaluated if used directly
// inside a string in single quotes $string = ` engineer` ; echo `This is a portal for $string. ` ; echo "" ;  
// / n will be displayed unchanged
// special meaning. echo `This is a portal for engineer. ` ; ?>
Output:
I am a geek. It`ll be interesting to know about the string. A is named as backslash. This is a portal for $string. This is a portal for engineer. 
Double quoted strings:double quoted strings cause PHP code to evaluate the entire string. The main difference between double quotes and single quotes is that with double quotes, you can include variables directly in the string. It interprets Escape sequences. Each variable will be replaced with its own value.The program below illustrates lineswithin double quotes:
Program 2: < td class = "code">  
// Simple string. echo "I am a geek . " ; echo " " ;  
// Nothing extra here echo "It`ll be interesting to know about the string." ; echo " " ;  
// / n works here echo "This is a simple string." ; echo " " ;  
// Variables included directly $string = `ABC` ; echo "The word is $string." ;  
?>
Output:
I am a geek. It`ll be interesting to know about the string. This is a simple string. The word is ABC. 
Get Solution for free from DataCamp guru