When to use single or double quotes
I read an interesting little code tidbit the other day on www.zenperfect.com about when you should use which quotes where in php. Nobody has ever explained this to me an it all makes sense now.
Basically, because php is an interpreted language, any variables that need to be calculated at runtime takes time. Using single quotes implies that the statement doesn’t need further processing. Using double quotes infers that there’s a variable that needs to be parsed within the quotes. For example:
$var1 = 'hello'; // string requires no processing
$var2 = "$var1 world"; // string requires processing, evaluates variable
$var3 = "String within double quotes"; // needlessly processed - no variable in string
You’re currently reading “When to use single or double quotes”, an entry on Monkey Business
- Published:
- 03.24.09 / 9pm
- Category:
- PHP
- Tags:



