Change language

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. ’ ; ?>
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:  
// 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." ;  
I am a geek. It’ll be interesting to know about the string. This is a simple string. The word is ABC. 


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Best laptop for engineering student


Best laptop for development


Best laptop for Cricut Maker


Best laptop for hacking


Best laptop for Machine Learning


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers


Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method