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

Hannah Schauer
Hannah Schauer
1,137 Points

Says "I forgot to add a space between first and last name"

I'm trying to make the full name read as the first and last name in the string set but I'm not sure why it is incorrect because I have a space there.

index.php
<?php

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

?>

4 Answers

Blayne Holland
Blayne Holland
19,321 Points

Try this.

$fullname .= $firstName . " " . $lastName ;

Hannah Schauer
Hannah Schauer
1,137 Points

That did not seem to work

Fahad Mutair
Fahad Mutair
10,359 Points

hello Hannah Schauer , you have to put space like this ' then space and close it with '

<?php

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

?>
Bapi Roy
Bapi Roy
14,237 Points

Follow this

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

remove dot after $fullname

Fahad Mutair
Fahad Mutair
10,359 Points

thanks for correction >.<

Blayne Holland
Blayne Holland
19,321 Points
  • 1 on this. This worked for me...
Benjamin Larson
Benjamin Larson
34,055 Points

Not sure if this was resolved -

Your problem is likely centered around the usage of the concatenation assignment operator: .= This should be distinguished from the plain assignment operator =, which only assigns a new value to a given variable. In this case of strings, using .= will tack on a new value to the end of whatever previous value was stored in that variable. and then reassign that concatenated (combined) string value back into the same variable. Essentially, one replaces the value and other adds to it.

For example:

<?php
// Plain Assignment Example
$fruit = "apple";
$fruit = "banana";
echo $fruit // Displays: banana
// Concatenation Assignment Example
$fruit = "apple";
$fruit .= "banana";
echo $fruit // Displays: applebanana
?>

In this case, you should just use the plain assignment operator in all instances. The value being stored in $fullname the way you have it is: "RasmusRasmus Lerfod". As well, PHP will complain a bit if you try to use .= on a variable which has not already been assigned a value. Usage of that operator inherently assumes you are adding on to an existing variable and it does not make sense to use it if no value has yet been assigned. It's like you're constantly adding a number to nothing. It doesn't really make sense to do so, so PHP gives you a little notice to double-check if you are doing an intended action.

Fahad has a correct solution if you check his code. Alternatively, you could use double-quotes around the string and you wouldn't need the concatenation operator at all.

<?php

//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';
$fullname = "$firstName $lastName";
?>
Fahad Mutair
Fahad Mutair
10,359 Points

Great explanation ill vote for you

Bapi Roy
Bapi Roy
14,237 Points

Try this $fullname = $firstName . " ".$lastName ;

You cannot concrete variable with declaring.

Hannah Schauer
Hannah Schauer
1,137 Points

<?php

//Place your code below this comment $firstName .= 'Rasmus'; $lastName .= 'Lerdorf'; $fullname = $firstName ."".$lastName ; ?>

This still is not working