Single and double quotes in PHP

There is a difference in the way that PHP handles single and double quote marks when using the echo statement.

For example :

$var = ‘test’;

The statements echo(‘$var’); and echo(“$var”); will generate different results.

echo “\$var is equal to $var”;

will display $var is equal to test

While :

echo ‘\$var is equal to $var’;

will display

\$var is equal to $var.

In the case of the sinlle quotes, the variable name is displayed as is.

Leave a Reply