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 trialPerry Cox
PHP Development Techdegree Student 1,442 PointsFinal 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
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
54,971 PointsGo 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
28,690 PointsYour code will not satisfy the requirements as it is echo
ing 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 echo
ing the name
value in each child Array.
The final step is to only output the flavor name when it is in_stock
.
Perry Cox
PHP Development Techdegree Student 1,442 PointsSean,
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
28,690 PointsPerry Cox sorry for the confusion on my part. Good job on trying to do something about the bug then!
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsCan you post your code?