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

enhancing a simple php-application /adding search controller view / accounting for empty results Challenge 3/3

Question "Let's make sure that foreach loop executes correctly if the $flavors array is NOT empty. Add one element to the $flavors array with a value of 'Avocado Chocolate'."

I feel this should be the easiest thing, but I'm so confused over it. Here's my code.

<?php

    $recommendations = array("Avocado Chocolate");

?><html>
<body>

    <h1>Flavor Recommendations</h1>
    <?php if(!empty($flavors)) { ?>
    <ul>
        <?php foreach($recommendations as $flavor) { ?>
            <li><?php echo $flavor;  ?></li>
        <?php } ?>
    </ul>
    <?php } else { ?>
        <?php echo '<p>There are no flavor recommendations for you.</p>'; ?>
    <?php } ?>

</body>
</html>

Please help, it's the wording that confuses me.

1 Answer

You gave the wrong name to the variable holding the array.

That's the thing. this was correct for the first two questions, for the third question all I added was "Avocado Chocolate", when I tried to create a new $flavors array and pass the string through there it said that "task one was no longer passing"

Never mind, I figured it out. Thanks for your help.