Single vs Double Quotes
PHP gives you two everyday ways to write a string literal, and they are not interchangeable stylistic choices — they parse differently. Single quotes are almost entirely literal: what you type is what you get. Double quotes are "smart": PHP scans the contents for variables to interpolate and escape sequences to convert before the string is built. Picking the right one for the job, rather than defaulting to one everywhere, makes your intent obvious to anyone reading the code.
Single quotes: almost completely literal
Inside single quotes, PHP recognizes exactly two escape sequences: \\' (a literal single quote) and \\\\ (a literal backslash). Everything else — including a $variable, a \n, or a \t — is printed exactly as typed, with no special meaning at all.
single-quotes.php
<?php $name = 'Sam'; echo 'Hello, $name!'; echo PHP_EOL; echo 'A tab looks like this: \t (not an actual tab)'; echo PHP_EOL; echo 'It\'s a literal apostrophe'; echo PHP_EOL; echo 'A backslash: \\';
Hello, $name! A tab looks like this: \t (not an actual tab) It's a literal apostrophe A backslash: \
Double quotes: variable interpolation and escapes
Inside double quotes, PHP replaces $variable (and the more
elaborate {$expr} form) with its current value, and it converts
backslash sequences like \n (newline), \t (tab), \" (literal
double quote), and \$ (a literal dollar sign, when you need to stop
interpolation) into their real characters.
double-quotes.php
<?php $name = 'Sam'; $price = 19.99; echo "Hello, $name!"; echo "\n"; echo "The price is \$price literally, but interpolated: $price"; echo "\n"; echo "Line one\nLine two\tTabbed";
Hello, Sam! The price is $price literally, but interpolated: 19.99 Line one Line two Tabbed
The full interpolation syntax — including the {$obj->prop} and
{$arr['key']} forms for anything more complex than a bare variable
— has its own dedicated page, since there are a few rules worth
seeing in isolation.
Side-by-side comparison
Feature | Single quotes '...' | Double quotes "..." |
|---|---|---|
Variable interpolation | No — printed literally | Yes — $var and {$expr} |
Escape sequences | Only ' and \ | \n, \t, \r, ", $, \, and more |
Readability for plain text | Very clear, nothing to scan for | Requires scanning for $ and \ |
Best for | Literal text, regex patterns, no interpolation needed | Building strings from variables |
The performance myth
Use single quotes for text with no variables or escapes — it's the most literal, least surprising option.
Use double quotes whenever you need to interpolate a variable or want
\n/\tto become real whitespace.Escaping a literal $ inside a double-quoted string requires $, or switch to single quotes if there's nothing else to interpolate.
Neither style meaningfully affects performance in real applications.