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 trialEitay Zilbershmidet
3,942 PointsWhy do I need this "$email_body" empty var?
<?php $name = $_POST["name"]; $email = $_POST["email"]; $details = $_POST["details"];
echo "<pre>"; $email_body = ""; $email_body .= "name " . $name . "\n"; $email_body .= "email " . $email . "\n"; $email_body .= "details " . $details . "\n"; echo $email_body; echo "</pre>"; ?>
Also, I don't understant why the var print all the information, isn't it should be reset after every line of code?
2 Answers
David Andrews
17,403 PointsYou are building the $email_body variable using string concatenation (appending the right hand string to the left hand string stored in the variable.)
$email_body = "";
$email_body .= "name " . $name . "\n";
$email_body .= "email " . $email . "\n";
....
The first line is setting $email_body to an empty string. The second line is concatenating ( with .= ) the right hand string to $email_body. The third line is again concatenating. The end result is a full listing of the strings stored in the $email_body variable.
Link to the PHP Manual Reference
Eitay Zilbershmidet
3,942 PointsHi,
Now I get it. Thank you for the answer :)