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 trialLeigh Maher
21,830 PointsA 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
Courses Plus Student 21,242 PointsHi, 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
21,830 PointsThanks Ryan. I had actually tried concatenation and saw that it worked, too. I'm probably use that method, too.