Using single quotes versus double quotes (explanation?)

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
xpiamchris
Forum Newbie
Posts: 10
Joined: Thu Jan 15, 2009 4:17 pm

Using single quotes versus double quotes (explanation?)

Post by xpiamchris »

So i was trying to debug this code:
header('Location: http://secure.mysite.com/managepicture.php?var=$var');

and realized by changing the single quotes to double quotes, it worked... But how do you know when to use single quotes and when to use double quotes?

Best,
Chris
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Using single quotes versus double quotes (explanation?)

Post by andym01480 »

Single quotes is as is.
Double quotes allows variables like $var to be interpreted for value rather than just as a sequence of characters.

another example

Code: Select all

$hello='Hi';
echo "$hello"; //outputs Hi
echo '$hello'; //outputs $hello
Post Reply