Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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