Thursday, July 8, 2010

single-quote( ' ) vs double-quote ( " ) in PHP

Difference between single-quote( ' ) and double-quote ( " ) strings in php

Briefly:
In double-quoted strings, variables are replaced by their values:
PHP Code:
$word = "Hello".
echo "$word there!"

The above code will output:
Hello there!

Doing the same with single quotes:
PHP Code:
$word = "Hello".
echo '$word there!'

...will print:
$word there!

Using single quotes where possible, will be slightly more efficient to process, because PHP doesn't have to search single quoted strings for variables.

No comments: