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 Build a Simple PHP Application Adding a Contact Form Working with Get Variables

Giovanni Valdenegro
Giovanni Valdenegro
13,871 Points

Why did you equal the

Why equal the variable $email_body to itself?

What is the difference of this:

$email_body = $email_body . "Name: " . $name . "\n"; $email_body = $email_body . "Email: " . $email . "\n"; $email_body = $email_body . "Message: " . $message; echo $email_body;

AND

This:

$email_body = "Name: " . $name . "\n"; $email_body = "Email: " . $email . "\n"; $email_body = "Message: " . $message;

Thanks

4 Answers

Ron McCranie
Ron McCranie
7,837 Points

This method is used so you can expand on the existing variable name. It's called concatenation. Every time you use an existing variable followed by a dot (.) your appending that data to then end of it. It could get confusing if you create a new variable name every time you just need to add a little more to an existing variable. Plus, in this example you want to start a new line every time you have a new line break \n

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

In the first instance, you're concatenating information onto the original variable...adding strings to the end...effectively building up the email piece by piece. In the second example, you're simply overwriting the $email_body variable over and over again, so you end up with just the Message bits.

Abdulla Alshubbar
Abdulla Alshubbar
31,298 Points

Because you want to build on the previous code with some new code. Otherwise you will override it (i.e. the old code will disappear and only the new one will be there).

Giovanni Valdenegro
Giovanni Valdenegro
13,871 Points

Thank you guys makes perfect sense now.