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

i cant solve this

<?php $flavors=array("Chocolate","Vanilla","milk");

?> <p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo "3"; ?> flavors of ice cream.</p> <ul> <?php foreach($flavors as $flavor){?> <li><?php echo $flavor1; ?></li> <li><?php echo $flavor2; ?></li>} </ul>

2 Answers

<li><?php echo $flavor1; ?></li>
<li><?php echo $flavor2; ?></li>}

OK, firstly, you're calling a variable that doesn't exist. Which is $flavor - the variable containing the array is $flavors.

Secondly, you're actually technically calling two variables that don't exist - $flavor1 and $flavor2.

To call specific items in an array you need to add square brackets to the end of the array variable, so if we want to call the first two items / flavors in the array, we do this:

<li><?php echo $flavors[0]; ?></li>
<li><?php echo $flavors[1]; ?></li>

This should work.

First, you need to format your code quote using the Markdown Cheatsheet syntax below. It will make your code readable.

I think you are stuck on step 4. You need to substitute out the number 2 for a dynamic way that will change based on the number of items in the array. Rather than just giving you the code to quote, I will tell you that you need to use the count() function. Here is the documentation for the function. Let me know if you still have problems.

DO it the dynamic way. Much better.