PHP PHP Arrays and Control Structures PHP Loops Looping with PHP

Perry Cox
Perry Cox
PHP Development Techdegree Student 1,442 Points

Final accepted output incorrect. How to report it?

I struggled with this output as it did not function correctly. I would work and test stuff out in atom on my own and successful out puts on the treehouse side echoed out array on the atom side. Things that worked on the atom side failed to satisfy the question. The final output that I submitted that the website said was correct actually prints out the word array 10 times

Perry Cox
Perry Cox
PHP Development Techdegree Student 1,442 Points
<?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 $v1) {
    foreach ($v1 as $v2) {
        echo "$v1\n";
    }
}
?>

2 Answers

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,288 Points

Go to support page https://teamtreehouse.com/support. There you find you can send a link to the challenge and your code to help@teamtreehouse.com.

Sean T. Unwin
MOD
Sean T. Unwin
Treehouse Moderator 28,648 Points

Your code will not satisfy the requirements as it is echoing the child Array, not the name string of the child Array.

The second step, after creating the foreach loop, is requesting to output each of the flavors. This will require echoing the name value in each child Array.

The final step is to only output the flavor name when it is in_stock.

Perry Cox
Perry Cox
PHP Development Techdegree Student 1,442 Points

Sean,

Yes, this code is not correct. I had written a piece of code that executed the assignment correctly but was not accepted by the website. I looked through the manual at the foreach and the piece of code I shared here did not function correctly but was accepted as a correct answer. I modified my original code and was able to get that accepted as well, but I needed to know how to let treehouse know that a wrong answer can be submitted, which KRIS linked me to.

Sean T. Unwin
Sean T. Unwin
Treehouse Moderator 28,648 Points

Perry Cox sorry for the confusion on my part. Good job on trying to do something about the bug then! :thumbsup: