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 Basics Daily Exercise Program Strings

Not Understanding the Meaning of Expand in PHP Strings Single vs. Double Quotes

I just finished watching: https://teamtreehouse.com/library/strings and Alena said that the difference between single vs. double quotes in a string is one expands the string and the other does not. However, she never explained what expanding in this case means.

My only guess is that it appears that single quotes around strings will keep the variable name if you put a variable in your string whereas double quotes will reveal the assignment of that variable (so instead of Hello $name it'll be Hello Xenomorph).

However, I'm still not seeing how exactly the word expand relates to this... Thanks for your help!

1 Answer

I assume she means the variable will be evaluated. As you said, when using double quotes, whatever is assigned to the variable will be displayed in place of the variable name.

For example:

<?php

$name = "Dave";

echo 'His name is $name';
// outputs: His name is $name

echo "His name is $name";
// outputs: His name is Dave

?>

A good explanation:

what is the difference between single quoted and double quoted strings in php

Hope this helps :)

Hi James! Your comment helped me out a lot!!! Thanks for the visual and additional information as well. :-)

DavidPaul sullivan
DavidPaul sullivan
17,377 Points

I had this same question, thanks James this was super helpful