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

Joshua Criddle
Joshua Criddle
1,255 Points

combination of fullname and the words

how to combine the fullname and the words

index.php
<?php

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

$fullName = "$firstName $lastName";

$fullName .= ' was the original creator of PHP.'."\n";

echo $fullName;

?>

2 Answers

Luc de Brouwer
seal-mask
.a{fill-rule:evenodd;}techdegree
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 Points

Hi Joshua,

In order to combine variables you have to use concatenation. To answer your question :

<?php
$firstName = "Rasmus";
$lastName = "Lerdorf";
$fullName = $firstName . " " . $lastName;

echo $fullName . " was the original creator of PHP. \n";
?>

You are trying to put 2 variables as a string into a variable, however it doesn't quite work like that. PHP requires you to concatenate, a chique word for 'combining' values from two variables into one, or into one string. In PHP we use the DOT to define you are trying to extend or combine your string, so if you look at my code example you will see that it will work and why it's done this way

<?php 

$fullName = "$firstName $lastName";

?>

Last but not least, as a tip try to look for answers first on the community before asking the same question : https://teamtreehouse.com/community/1-use-the-fullname-variable