Page 1 of 1

When use single quote and when double quote

Posted: Wed Apr 26, 2006 4:33 am
by lostinfog
This is a newbie question.
I began to use PHP one month ago.
I found in many cases, single quote and double quote are interchangable just like below.
$var='avalue';
or
$var="avalue";

When a double quote is needed to be embeded into another double quote, sometimes I change the double quote into single one and it's ok. Sometimes I use backslash before the embeded double quote, it also works.
echo "<input name='submit' value='submit' />";
or
echo "<input name=\"submit\" value=\"submit\" />";
I'd like to know what's the different use case for single quote and double quote.
Thanks!

Re: When use single quote and when double quote

Posted: Wed Apr 26, 2006 4:40 am
by Zythan
Hello,

Take a look here, I think that everything is explained very well.

http://www.netcode.net/tutorials/php_my ... quotes.php

HTH

Zythan

Posted: Wed Apr 26, 2006 5:16 am
by shiznatix
there was some massive testing done before in another thread and the result was:

use either, they are both just as fast. just stick to one and use it consistantly, don't just between the 2. i personally use single because it is generally easier to read

Posted: Wed Apr 26, 2006 7:02 am
by neophyte
I agree with Shiznatix... use them consistantly.

I hate it when people do something like this:

Code: Select all

$var = "I need a $variable inserted here".some_func_goes_here('somevar', "somefoo").'Then some html <div id="blah">'.$foobar."</div>";