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 do I combine first name string and second name string to get the value to show for the full name string?

Hi, I am a huge noobie with this stuff, I am stuck on how to show the value for my full name string of the firstname and last name string.

index.php
<?php

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

2 Answers

andrewgabriel
andrewgabriel
18,106 Points

The way you add two or more strings together, you use .

$firstName = 'Rasmus';
$lastName = 'Lerdorf';
$fullname = $firstName . " " . $lastName;

You see how I added an empty space string in between both variable in order to leave spacing between then and used the dot to append them and store it in $fullname

Hope that helps :)

Thank you so much, Andrew! This was very helpful, as I did not realize you had to concatenate the space. I was receiving the space error, so thanks so much. Also would you know why $fullname is not capitalized like $firstName and $lastName?

andrewgabriel
andrewgabriel
18,106 Points

Ryan Caracciolo There is no specific reason as to why it's not named $fullName however naming variables depends on whoever is writing code. It's best to practice writing names where you capitalize the first letter of every word after the first one however you will come across people who don't so don't let it confuse you. Just make you follow best practices which you are since you noticed this right away. Keep up the good work!

Thank you so much again Andrew! I really appreciate the help!