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 statements give me same output.
In PHP, people use single quote to define a constant string, like 'a' , 'my name' , 'abc xyz' , while using double quote to define a string contain identifier like "a $b $c $d" . echo "my $a"; This is true for other used of string.
Using " is the way to do it.
I believe that double quotes allow variables to be replaced by the value :
echo "test = $test";
displays :
test = 2
echo 'test = $test';
displays :
test = $test
Single-quoted strings will not have variables or escape sequences expanded by the interpreter, whereas double-quoted strings will - look at the different output of:
$foo = 'bar';
echo 'This is a $foo';
echo "This is a $foo";
Single-quoted strings are hence marginally 'better' to use as the interpreter won't have to check the contents of the string for a variable reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With