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 PHP Basics (Retired) PHP Conditionals & Loops Foreach Loops

Joseph Casey
Joseph Casey
6,782 Points

A source covered in <?php?> seems awful impractical.

Is there something that is found in later lessons which can substitute for the heavy usage of opening and closing php scripts everywhere? Something about that seems off, but I'm not sure what it is.

2 Answers

Robert Komaromi
Robert Komaromi
11,927 Points

The only alternative is to not use PHP in your templates, or try a PHP templating engine like Twig or Blade. Also, you shouldn't be doing any logic in your templates / HTML documents with PHP. You should use it for conditionally displaying something, iterating through a list to be displayed, showing specific variables (ex. a username), etc.

Ian Hudson
Ian Hudson
13,457 Points


I just started to study "MVC Frameworks for PHP". Among other things, this helps to organize your code and cut down on redundancy as well. The following link may explain what it is, and how/why its used.


Hope that helps,