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
Shaun Kelly
35,560 PointsStuck on php question! Can anyone tell me the answer then explain there answer? thanks
Create a variable called fullName and assign it a value equal to the concatenation of the firstName variable, a space, the middleName variable, a space, and the lastName variable.
Here is the code i have:
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = "firstName " . "middleName " . "lastName";
echo "The designer at Shirts 4 Mike shirts is named ____";
?>
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsYou are assigning the string values "firstName", "middleName", and "lastName" to $fullName not the variables. You don't have the dollar signs in front of the variable names. So they are evaluated as strings and not variables.
$fullName is going to equal firstName middleName lastName
This would work:
$fullName = "$firstName " . "$middleName " . "$lastName";
but I don't believe the difference between using double quotes and single quotes is covered in the project. When using double quotes in php, variables are evaluated. With single quotes, they are not.
That could be simplified to this too:
$fullName = "$firstName $middleName $lastName";
The other way that would be more inline with what is taught is to simply concatenate all the variables together along with spaces between.
$fullName = $firstName . " " . $middleName . " " . $lastName;