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> Link to comment https://forums.phpfreaks.com/topic/279922-echo-value-from-one-array-based-on-the-result-of-conditional-involving-another-array/ 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. Link to comment https://forums.phpfreaks.com/topic/279922-echo-value-from-one-array-based-on-the-result-of-conditional-involving-another-array/#findComment-1439720 Share on other sites More sharing options...
_EmilsM Posted July 6, 2013 Share Posted July 6, 2013 <?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'); Link to comment https://forums.phpfreaks.com/topic/279922-echo-value-from-one-array-based-on-the-result-of-conditional-involving-another-array/#findComment-1439721 Share on other sites More sharing options...
sonnyj7 Posted July 7, 2013 Author Share Posted July 7, 2013 Thanks for the clarity EmilsM! Link to comment https://forums.phpfreaks.com/topic/279922-echo-value-from-one-array-based-on-the-result-of-conditional-involving-another-array/#findComment-1439732 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. Link to comment https://forums.phpfreaks.com/topic/279922-echo-value-from-one-array-based-on-the-result-of-conditional-involving-another-array/#findComment-1439750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.