PHPSingle vs Double Quotes

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
<?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
<?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
Single quotes are not meaningfully faster
You'll still see advice online claiming single-quoted strings are "faster" than double-quoted ones because they skip the interpolation scan. In modern PHP (7+ and especially with OPcache in production), the difference for realistic code is immeasurably small — the interpreter compiles the string once, and the interpolation check happens at compile time, not on every request. Do not sacrifice readability chasing a micro-optimization that doesn't move the needle; choose quotes based on whether you need interpolation.
  • 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/\t to 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.

A common gotcha with arrays inside double quotes
`"$arr[key]"` works without quoting the key inside a double-quoted string using the *simple* interpolation syntax — but only for a bare key, and it can be visually confusing next to real array syntax elsewhere. Many teams prefer the explicit `"{$arr['key']}"` curly form specifically to avoid this ambiguity; see the interpolation page for the full rule.
Tip
A practical default many teams adopt: use single quotes as the baseline for any string, and reach for double quotes only the moment you actually need interpolation or an escape sequence. This makes double-quoted strings a visual signal — "something dynamic is happening here" — instead of noise everywhere.