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 Functions Introducing Functions PHP Function Arguments

Leigh Maher
Leigh Maher
21,830 Points

A variable within a string?

It seemed odd to me that he was able to put a variable within the string at start of this video, but it does work fine. Is this the normal way to do do it? Shouldn't the interpreter see everything inside a string as part of the string?

2 Answers

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,240 Points

Hi, Leigh. In PHP, you can reference variables inside of strings that are enclosed with double quotes, but not single quotes. Personally, I prefer concatenation when working with strings and variables since it makes things easier to tell apart, especially when coming back to code after some time has passed.

Leigh Maher
Leigh Maher
21,830 Points

Thanks Ryan. I had actually tried concatenation and saw that it worked, too. I'm probably use that method, too.