What is the difference between single quote and double quote string in PHP?

In PHP a string can be written in single quotes or double quotes. They work differently:

Single quotes (‘ ‘)Double quotes (” “)
Text is used exactly as writtenVariables inside are replaced with their values
Only \' and \\ are specialEscape codes like \n, \t and \" work
Good for plain textGood when you need variables inside the text
<?php
$name = "Robin";

echo 'Hello $name' . "<br>";
echo "Hello $name" . "<br>";
echo "Price: {$name}s";
?>

Output:

Tutorials Class - Output Window

Hello $name
Hello Robin
Price: Robins

The curly braces in the last line mark where the variable name ends.

Note: You may read that single quotes are faster. The difference is so tiny that you will never notice it, so choose by need, not by speed. For long text on many lines use heredoc (like double quotes) or nowdoc (like single quotes). See PHP String Handling.

Learn more about the similar topics:
Tutorials
PHP String Handling
PHP explode() Function
PHP strpos() Function
PHP implode() Function
Exercises & Assignments
Write a PHP program to reverse the string
Write a PHP program to find the length of the string
Write a PHP program to count the words in the string
Write a PHP program to convert a string into uppercase
Interview Questions & Answers
How will you concatenate two strings in PHP?
What is the difference between single quote and double quote string in PHP?
Why we use PHP String functions trim(), ltrim() and rtrim()?
What PHP Function is used to find position of a string?
What is the use of ucwords() PHP String function?
What is the use of str_replace() PHP String function?
How to find String Length in PHP?