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 trialPiotr Manczak
Front End Web Development Techdegree Graduate 29,277 PointsUsing foreach loop. I got a requested effect. I echoed each of the flavors into the screen. I can't get through.
I also used var_dump(). Nevertheless I couldn't get through.
<?php
$flavors = array();
$flavors[] = array("name" => "Cookie Dough", "in_stock" => true);
$flavors[] = array("name" => "Vanilla", "in_stock" => false);
$flavors[] = array("name" => "Avocado Chocolate", "in_stock" => false);
$flavors[] = array("name" => "Bacon Me Crazy", "in_stock" => true);
$flavors[] = array("name" => "Strawberry", "in_stock" => false);
//add your code below this line
foreach ( $flavors as $key => $item ) {
echo '<pre>';
echo implode($item);
echo '</pre>';
}
?>
1 Answer
Piotr Manczak
Front End Web Development Techdegree Graduate 29,277 PointsTry this: foreach ( $flavors as $item ) { if ( $item['in_stock'] ) { echo $item['name']; } }
Piotr Manczak
Front End Web Development Techdegree Graduate 29,277 PointsPiotr Manczak
Front End Web Development Techdegree Graduate 29,277 PointsIt says: "You are not using the variable you defined in the foreach loop.".