The ultimate guide for single vs. double quotes in PHP

twitter logo github logo ・1 min read

After many hours of reading, benchmarking and getting deep in the internals of PHP, I can finally bring you the truth:

Just use whatever is easier to type on your keyboard.

That's all for me today, thanks for coming, have a nice day :)

twitter logo DISCUSS (3)
markdown guide
 

IIRC PHP does not interpolate variables in single quotes. So the ultimate guide is:

  1. Double quotes if you "need $variables" in your string (and you don't want 'to' . 'join' . $them)
  2. Single quotes for everything else.
 
 

Well, single quotes are slightly faster than double quotes (if that matters for your script).

Classic DEV Post from May 10

If you could change one thing about learning to code, what would it be?

If you could wave a magic wand and make your biggest challenge when you were lear...

eLabFTW profile image
Dev of eLabFTW, a free and open source laboratory notebook.
Join dev.to

Guaranteed to make you a better developer or your money back