sonnyj7 Posted July 6, 2013 Share Posted July 6, 2013 Let's assume that there is an EMPTY "$flavors" array that has already been established...Here's the problem: 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 can't seem to figure this out -THIS IS AN EXERCISE) Here's the STARTER code to the problem: <?php $recommendations = array(); // This is the code that I added $flavors = array() $flavors = array("Avocado Chocolate"); ?><html> <body> <h1>Flavor Recommendations</h1> <?php if (!empty($flavors)) { echo '<ul> <?php foreach ($recommendations as $flavor) { ?> <li><?php echo $flavor; ?></li> <?php } ?> </ul>' ; } else { echo '<p>There are no flavor recommendations for you.</p>'; }?> </body> </html> Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 6, 2013 Share Posted July 6, 2013 Do your own homework, that's how you learn and pass the final exam. Quote Link to comment Share on other sites More sharing options...
_EmilsM Posted July 6, 2013 Share Posted July 6, 2013 (edited) <?php $recommendations = Array("Avocado Chocolate"); if(!empty($recommendations)) { echo '<ul>'; foreach($recommendations as $flavor) { echo '<li>'.$flavor.'</li>'; } echo '</ul>' } ?> .. and you can add to the recommendations array if you want.. $recommendations[] = 'flavor'; or $recommendations = Array('flavor1', 'flavor2', 'flavor3'); Edited July 6, 2013 by _EmilsM Quote Link to comment Share on other sites More sharing options...
sonnyj7 Posted July 7, 2013 Author Share Posted July 7, 2013 Thanks for the clarity EmilsM! Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 7, 2013 Share Posted July 7, 2013 Yes, they can come work with you and you can do their work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.