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 trialNathan Boaldin
Courses Plus Student 12,545 PointsMy php concatenation not working?
Why does this not work?
<?php
//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';
$fullName = "$firstname .' '. $lastName";
?>
The error thrown says: Bummer! $fullName should equal Rasmus Lerdof. Lerdof != Lerdorf. Is this the issue?
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! No, the spelling of the name is not the issue although, I feel like that Bummer! message should be corrected. If you wanted to concatenate two string literals, you'd put the two strings then a period and then the next string. For instance:
$greeting = "Hi there, " . "Nathan";
The end result would be that the variable $greeting
would hold the string "Hi there, Nathan". Strings start and end with either double quotes or single quotes, but they must match on both sides. That being said, concatenation is not really needed here. You can use the double quotes feature of PHP to expand the values of the variable.
$yourFirstName = "Nathan";
$yourLastName = "Boaldin";
$yourFullName = "$yourFirstName $yourLastName";
This is very similar to the challenge, and I think you can get it with these hints. Hope this helps!
Nathan Boaldin
Courses Plus Student 12,545 PointsNathan Boaldin
Courses Plus Student 12,545 PointsThank you so much for your help! With JS is where I first learned to concatenate strings, so php is confusing me a bit. lol. FWIW, would this work:
$fullName = $firstName .' '. $lastName;
Anyway. Thanks, again!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherNathan Boaldin Yup! That would've worked splendidly as well. I know, the
.
as a concatenation operator is a little special. I'm not sure that I've come across any other language yet that uses a dot over a +.