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 Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying Item Details

Bence Szatmári
Bence Szatmári
9,235 Points

I don't understand this.

Hi! I want to ask why do we write this if statement here:

<?php

if(strtolower($item['category']) == 'books'){

?> <-----

<?php } ?> <---

Why are we put php open and closing tags where i put the arrows? I hope you can understand what is my problem .

2 Answers

The reason being is so you can insert HTML. This means that any HTML you put in there, will only appear if your statement is true.

Bence Szatmári
Bence Szatmári
9,235 Points

So we are using this because we are not using 'echo "<tr>"' just simple html tags and it will only appear if our statment is true?

Bence Szatmári
Bence Szatmári
9,235 Points

I think I can understand now ! Thank You!

This works for any other code block too. You can use it in functions and loops. It's pretty useful to use straight html and not have a bunch of echoes. Also makes it more readable.