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 PHP Basics Daily Exercise Program String Manipulation

How to combine 2 variable value with space in the middle into a string ?

I am having difficulty in passing this test, Task 2 of 3. Which it alerts me an error.


//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';

$fullname =  ' .$firstName .$lastName .';

2 Answers

You're close but a little off.

$fullname = $firstName . ' ' . $lastName;

The way that I learned it was to think of the periods as glue that hold different things together.. So you're gluing the first name to a space, and then on the other end you're gluing the space to the last name to form one full string.

You can also do it this way, which I prefer:

$fullname = "$firstName $lastName";

You have to use double quotes, but the variables and the space between them gets printed out. Cool!

Curly braces are optional here, but I like using them as it helps readability! :)

$fullname = "{$firstName} {$lastName}";