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

Where am i going wrong here on Task 7 OF STAGE 4:

Below is my what i did

<?php

$flavors = array("Chocolate", "Vanilla", "Strawberry", "Cookie Dough");

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

flavors.php
<?php

    $flavors = array("Chocolate", "Vanilla", "Strawberry", "Cookie Dough");

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

Your echo statement correctly at this stage shows '3', but your array at the top has four elements for some reason. The previous step only asked you to add your one favorite flavor.

Reformatted code:

<?php

$flavors = array("Chocolate", "Vanilla", "Strawberry", "Cookie Dough");
?> Welcome to Ye Olde Ice Cream Shoppe. We sell flavors of ice cream.

<?php foreach($flavors as $flavor) { echo "

" . $flavor . "
"; } ?>
flavors.php
<?php

    $flavors = array("Chocolate", "Vanilla", "Strawberry", "Cookie Dough");

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

Please refer to the Markdown Cheatsheet for future code quotes so it formats properly.

2 Answers

There are several problems with your code. The one that is stopping you at this step is that you have statically set the number ice cream to 3. While that is the correct number, the idea of the challenge is to set the number dynamically so that you don't have to update it as you add or subtract ice cream. So you need this:

<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?> flavors of ice cream.</p>

EDIT: this last part may be wrong. I have to check the correct order of the statement.

EDIT 2: Your foreach loops are correct. I had it backwards in my head. I am removing the incorrect section because I cannot seem to make it strike out.

You echo statement in the first foreach loop is unusual. While it is correct syntax, I am not sure it is what you want and whether it will pass the challenge. But the formatting of the quote makes it hard to know what your code really is.

oh i got it thanks a lot that helps