Single and double quote echo in PHP

Possible duplicate:
Difference between single quote and double quote string in php

Hi,

What is the difference between echo 'Test Data'; and echo "Test Data"; in PHP.

Both operators give me the same result.

+6
php quotes echo
source share
2 answers

I believe that double quotes allow you to replace variables with a value:

 echo "test = $test"; 

displays:

test = 2

 echo 'test = $test'; 

displays:

test = $ test

+10
source share

Single-quoted strings will not contain variables or escape sequences expanded by the interpreter, while double-quoted strings will look at other output:

 $foo = 'bar'; echo 'This is a $foo'; echo "This is a $foo"; 

Single-quoted strings are therefore marginally “better” to use, because the interpreter does not need to check the contents of the string for variable references.

0
source share

All Articles