Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Functions Function Returns and More PHP Closures

When to use double and single quotes

I'm a little confused when to use double quotes and when single.

Do we use double quotes when we have variables in our strings?

Any help would be much appreciated!

Thank you.

3 Answers

Tuukka,

They both basically do the same core thing...echo out a string. The big difference between the two is how it handles variables, functions, arrays, etc within. Single quotes will echo out the name of the PHP object while double quotes echo out the value it contains or performs the PHP object's functionality. Basically, single quotes will echo out what is inside of the string and double quotes will perform or echo any type of PHP function or container then echo out the result.

<?php

$var = 5;

echo 'This is the variable $var';  // This will output... This is the variable $var
echo "This is the variable $var";  // This will output... This is the variable 5

?>

Hope this helps.

Cheers!

Thank you so much Shawn!

Your answer is perfect. No more confusion :)

Have a great Week Shawn!

Robin Pedersen
Robin Pedersen
3,889 Points

What is more common to use on a regular basis?