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 Jan 25

Letter to Myself Ten Years Ago

Inspired by the viral 10-year challenge on social media, when people show the world what they looked like 10 years ago, I decided not to share my photos of that time.

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

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️