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 trialKumbirai Ruth Huni
4,209 PointsModify the foreach loop to display only the flavors that are in stock
Hi. I keep getting the response that task 1 is no longer passing after copying and pasting the code from task 1 and failing. Where could i be getting it wrong
<?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);
$order = array(
//add your code below this line
foreach($flavors as $item){
if($item ['in_stock']){
echo $item['name']."<br/> \n";
}
}
?>
1 Answer
Benjamin Larson
34,055 PointsHi Kumbirai -
Your code is correct, but you have an added line that shouldn't be included:
$order = array(
If you remove that one line, the rest of it should pass. Not sure where it came from, maybe you copied and pasted it by accident?
Antonio De Rose
20,885 PointsAntonio De Rose
20,885 Pointswhy is this below code line for