When use single quote and when double quote

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lostinfog
Forum Newbie
Posts: 8
Joined: Wed Apr 26, 2006 4:22 am

When use single quote and when double quote

Post 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!
Zythan
Forum Newbie
Posts: 16
Joined: Wed Apr 12, 2006 3:13 am

Re: When use single quote and when double quote

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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>";
Post Reply