Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics Daily Exercise Program String Manipulation

How do I combine $firstName = 'Rasmus'; and $lastname = 'Lerdorf'; to make $fullName = Rasmus Lerdorf?

String Manipulation

2 Answers

Steven Parker
Steven Parker
216,057 Points

Joining strings together is called "concatenation", which was explored in detail in the video on Combining Strings. You may want to review that video.

The operator symbol for concatenation is a period ("."). It essentially acts like "glue" sticking two strings together to make one longer one. You can combine as many as you want in a single statement, and they can be a mix of literals (things in quotes) and variables containing strings.

I'll bet you can get it now, without an explicit "spoiler".

$firstName = 'Rasmus';
$lastName = 'Lerdorf';

$fullName = $firstName.' '.$lastName;

Exactly as Steven Parker mentioned, but figured I would provide a demonstration of how you would specifically concatenate strings in PHP.