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 trialKyle Damken
10,633 PointsWhy is this wrong
It says "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 tested it on a my server and it works fine.
What's wrong here?
<?php
$recommendations = array('Avacado Chocolate');
?><html>
<body>
<h1>Flavor Recommendations</h1>
<?php if (!empty($recommendations)) { ?>
<ul>
<?php foreach($recommendations as $flavor) { ?>
<li><?php echo $flavor; ?></li>
<?php } ?>
</ul>
<?php } else {
echo '<p> There are no flavor recommendations for you. </p>';
}
?>
</body>
</html>
1 Answer
Tunde Adegoroye
20,597 PointsRather than having
<?php } else {
echo '<p> There are no flavor recommendations for you. </p>';
}
?>
try
<?php } else { ?>
<p> There are no flavor recommendations for you. </p>
<?php } ?>
What you wrote is fine it's just it can be funny since it wants you to break up the if and else statements
Kyle Damken
10,633 PointsKyle Damken
10,633 PointsAwesome! It worked, thanks man. It's such a pain when it can be that finicky.
Tunde Adegoroye
20,597 PointsTunde Adegoroye
20,597 PointsNo worries mate haha welcome to the world of PHP