Single vs double quotes in PHP: what is the difference?
Short answer
Double-quoted strings interpolate variables and process escape sequences like \n. Single-quoted strings are literal, apart from \\ and \'.
$name = "Dom";
echo "Hello $name"; // Hello Dom
echo 'Hello $name'; // Hello $name
echo "Line\nbreak"; // an actual newline
echo 'Line\nbreak'; // the characters backslash-n#Braces when the variable touches other text
echo "That is {$count}x faster"; // without braces, PHP looks for $countx
echo "Title: {$video['title']}"; // required for array access in strings
echo "Name: {$user->name}";Use braces by default inside double quotes. It costs two characters and removes a whole class of ambiguity.
#Heredoc and nowdoc
For multi-line blocks:
$html = <<<HTML
<div class="card">
<h2>{$title}</h2>
</div>
HTML;Heredoc (<<<HTML) interpolates like double quotes. Nowdoc (<<<'HTML') is literal like single quotes. Since PHP 7.3 the closing marker can be indented, and that indentation is stripped from every line.
#Does the performance difference matter?
No. The single-quote-is-faster advice is a micro-optimisation from a decade ago that is unmeasurable in any real application. Pick based on whether you want interpolation.