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

Accounting for Empty results 3 of 3

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

I don't know why but this question has just drained me. It shouldn't be difficult at all, but I just can't seem to get past this. I know I'm adding an element to the $recommendations correctly, but the code underneath must be wrong. What's upsetting me the most is that it passed the other two stages :(

What am I doing wrong?

<?php
 $recommendations = array();
$recommendations[] = 'Avocado Chocolate';

?><html>
<body>
<h1>Flavor Recommendations</h1>

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

2 Answers

Hi Derek - I see a couple of typos in your code. Recommendations is misspelled:

<?php foreach($reccomendations as $flavor) { ?>

AND

</hmtl>

Thanks Jennifer! silly mistake on my part