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

Question on Semantics(I think it's semantics...)

Hello All!

As I'm going through the PHP lessons I'm noticing that Randy will open up a php section and insert his variables then close it off. From there he'll open up another php section to write out more code. I'm specifically talking about the video "Introducing Arrays".

Now I know this is very trivial but I want to learn the "why" behind every detail. Why does he have two different php sections?? I just tried it all under one php tag and it worked just the same. Is he doing that just to make it easier to read or something?

Any input would be appreciated!

Thanks, Seth

3 Answers

A pure PHP file does not require the closing of tags. However, closing PHP tags in a file that also contains HTML, shows where PHP starts and stops.

  1. Official Documentation on PHP Tags

  2. Should You Close PHP Tags?

It's basically done for human readability. The server processes all of the PHP in the tags, ignores everything not in a PHP tag. It does whatever logic is in the PHP, and sends only the HTML from that file to the browser.

Thanks for the info guys. Appreciate it! Right after I got done with this I kept going with the PHP course and the next video explained it as well. I guess I'll wait a little longer next time before I ask questions :)