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 Concatenation and Whitespace

Frank D
Frank D
14,042 Points

Why $email_body = to itself and don't get overridden?

In this example Randy Hoyt shows a code like this:

$email_body = '';
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message . "<br>";

Why the variable $email_body must to be equal to itself and how come it doesn't get overridden by the other variables assigned (instead displaying multiple values)?

1 Answer

it is taking the currents version of the variable and adding the concatenated portion to it. just cleaner way to write it so you can read it and see what is going on.

$email_body = ' "Name: " . $name . "<br>" .  "Email: " . $email . "<br>" . "Message: " . $message . "<br>" ';

this is the same thing just a little harder to read.

Frank D
Frank D
14,042 Points

Oh I see, It is not overriding the value but it is adding other values by concatenation. Thanks a lot Shawn. Really helped!