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
Rossouw Strydom
12,398 PointsCode Challenge: Separating Concerns: Models
Hi I'm struggling with the second challenge 2/3 can someone please help me.
Next, let’s move the flavors array into that function. This task has two steps. (1) Move the code that creates the flavors array from [index.php] into the get_all_flavors() function in [flavors.php]. (2) Add code at the end of the function so that it returns the array of flavors back to whatever code calls it.
function get_all_flavors(){
$flavors = array();
return $flavors;
}
12 Answers
Kevin Korte
28,149 PointsYou have two files to work with on the challenge. Index.php and flavors.php.
In index.php at the very top, you will see an array called $flavors, with a bit a list of flavors in it. You have to select and cut that entire array, and than open up flavors.php and copy your $flavors array into it. Than, return $flavors.
The code you posted there, there is nothing in your array. You are missing the flavors. Add the flavors from the $flavor array into the the empty parenthesis and you should pass.
Matthew Floyd
7,413 PointsHere is step 3 as it worked for me. <?php foreach ($flavors as $flavor) { echo "<li>" . $flavor["name"] . ' +' . $flavor["likes"] . "</li>"; } ?>
Rossouw Strydom
12,398 PointsI cant believe it. I did that the first time and it did not work. Now when i did it it pass. Thanks again luckily I know I got it right the first time.
Kevin Korte
28,149 PointsNo prob! You were correct, you just didn't have your array values! :) Easy oversight!
Rossouw Strydom
12,398 PointsNow i need help with this code don't know why i struggle so much now. 3/3
Next, let's change [index.php] to call this function. Before the code that displays the list of flavors, call the get_all_flavors() function and assign the return value to a $flavors variable.
Marwa zada
UX Design Techdegree Student 15,460 PointsI'm a bit stuck on this part, any assistance?
Rossouw Strydom
12,398 PointsNvm i got it. :)
jeroenvandeudekom
10,840 PointsOk i'm stuck at part 3/3, anyone care to elaborate?
Olaf Gehrke
13,485 Pointsyeah i stucked at part 3/3 too and now i solved it and its pretty easy.
1.) there is a great hint in the following question part
Or
2.) the easy way:
assign your function to a variable and return this variable ... thats it.
$a = function abc(); return $a;
Marcin Robert Kaźmierczak
33,570 PointsIn index.php
<?php
require_once('flavors.php');
$flavors = get_all_flavors();
?>
Adam Zuckerberg
22,248 PointsAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH So CONFUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
AREGAGSSDKLDSGagdjsg;ldasgkjadsgdkjasgkjkjakjgsw3w@!@!!!@!!
Taylor Harris
2,717 Pointshey guys how did you pass the part 3?
Marcin Robert Kaźmierczak
33,570 PointsIn index.php
<?php
require_once('flavors.php');
$flavors = get_all_flavors();
?>
I souldn't answer that kind of questions... :)
Taylor Harris
2,717 PointsThank you so much! Added it in the wrong place lol.
CJ Williams
34,372 PointsOOOOPS. I was putting a $ in front of my get_all_flavors call.
<?php
require_once('flavors.php');
$flavors = $get_all_flavors();
?>