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 trialHannah Schauer
1,137 PointsSays "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.
<?php
//Place your code below this comment
$firstName .= 'Rasmus';
$lastName .= 'Lerdorf';
$fullname .= $firstName . $lastName ;
?>
4 Answers
Blayne Holland
19,321 PointsTry this.
$fullname .= $firstName . " " . $lastName ;
Fahad Mutair
10,359 Pointshello 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
14,237 PointsFollow this
$fullname = $firstName . ' '. $lastName ;
remove dot after $fullname
Fahad Mutair
10,359 Pointsthanks for correction >.<
Blayne Holland
19,321 Points- 1 on this. This worked for me...
Benjamin Larson
34,055 PointsNot 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
10,359 PointsGreat explanation ill vote for you
Bapi Roy
14,237 PointsTry this $fullname = $firstName . " ".$lastName ;
You cannot concrete variable with declaring.
Hannah Schauer
1,137 Points<?php
//Place your code below this comment $firstName .= 'Rasmus'; $lastName .= 'Lerdorf'; $fullname = $firstName ."".$lastName ; ?>
This still is not working
Hannah Schauer
1,137 PointsHannah Schauer
1,137 PointsThat did not seem to work