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


Jesse Stanton
Jesse Stanton
15,595 Points

Is this a good shortcut?

I'm working my way through the Simple PHP lesson and doing the segment on concatenating. In the video, Randy defines a blank variable called email_body, then adds the name, then adds the email, then adds the message. I'm pretty sure I copied his correctly, but it wasn't coming out right. So I simplified it all on to one line and just did:

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

And that worked perfectly. So now I'm wondering, am I cutting corners in a way that's going to come back to haunt me as I go on, or is this OK? This also seems more in line with how they have you do it in the challenge that follows.

1 Answer

Gareth Borcherds
Gareth Borcherds
9,372 Points

Either way works, it's more just a formatting issue. A lot of times what bites you in the butt is the space between words, so putting it on separate lines can help you see that the space is there correctly. It all comes down to preference though and what makes it easiest for you, just make sure that if you're sharing your code you make it readable and intuitive for those that need to look at it so that you don't have problems with collaboration because of different styles in how you group things together.