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

Christopher Simmons
Christopher Simmons
5,296 Points

Double or single quotations in PHP, especially with variables?

Should we just use double quotes all the time in PHP to be safe?

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

If you use single quotes in PHP, variable values will NOT be evaluated.

For Example:

$adjective = "Great";

'You are a $adjective Person' ==> will return You are a $adjective Person

but

"You are a $adjective Person" ==> will return You are a Great Person.

So, Yes, which quotes you use does matter in PHP. Variable will only evaluate the actual value inside of double quotes. They will NOT evaluate inside of single quotes. This is different from almost all other languages, but an important thing to remember.

Keep Coding! :) :dizzy:

Hmmm... This is a hard question. Personally, I enjoy always using double quotes, but when I have one tiny string like the letter a, I sometimes use single quotes. But keep in mind that either is fine. :)

~Alex

Christopher Simmons
Christopher Simmons
5,296 Points

I will use double quotes now to be on the safe