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 trial

PHP PHP Arrays and Control Structures PHP Loops Looping with PHP

Modify 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

index.php
<?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"; 
}
}
?>
Antonio De Rose
Antonio De Rose
20,885 Points

why is this below code line for

<?php
$order = array(

//take it off, and it would be all good, you have done, in the right way.

1 Answer

Benjamin Larson
Benjamin Larson
34,055 Points

Hi 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?