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 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.