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 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!