Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics Getting to Know PHP Intro to Workspaces and PHP Code

Single or doble quotation marks

When you write the code <?php echo "Hello World!"; ?> or <?php echo 'Hello World!'; ?> Why Alena Holligan used single quotation marks? or Can you use doble quotation marks? any difference.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Oscar! In this case, yes, you could use either single or double quotes. Either work for this example. The biggest difference is when you have a string containing a variable name in it. Let me show you an example and feel free to run this in a workspace!

<?php
 $hello = "Hello World!";
 echo "$hello";
 echo '$hello';
?>

If/when you run this code the first echo will actually echo out "Hello World!". It expands the variable to retrieve the value inside it and display the value. The single quotes don't do that. They simply echo out the variable name. So the second echo will echo out $hello.

She could have used either here and achieved the same results. But she had to choose one, and the single quotes is what she chose for this example. Hope this helps! :sparkles:

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Best answer assigned 2017-07-06 as no other answers are present and answer has been upvoted multiple times.