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 Simple PHP Application Listing Inventory Items More Excitement With Arrays

Inside the foreach loop, we should only display one <li> tag for each flavor. The one list item should display the value

I'm stuck.....

2 Answers

Carter Meyers
Carter Meyers
3,236 Points

In case the "one <li >" tag bit was confusing, what the instructions really mean is one "pair" of <li> tags, which is to say an <li> and an </li>.

Before you start the foreach loop, what you'll want to do is start the unordered list, as all we're going to be doing with the foreach loop is building the items within a single, not the list itself. Using the same logic, we'll end the unordered list (</ul>) only after our foreach loop has finished.

Therefore, the code we'd use would look like this:

<ul> <!-- We start our unordered list. -->
  <?php foreach ($flavors as $flavor) { ?> <!-- We start our foreach loop. -->

      <li><?php echo $flavor; ?></li> <!-- We tell the server what we want to do with each item in our array. In this case, convert it to an HTML list item. -->

  <?php } ?> <!-- We end our foreach loop.
</ul> <!-- We end our unordered list, as we've now finished displaying every item in our array.

yeah thanks from me too!

Thank you! Helped a bunch!