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 Enhancing a Simple PHP Application Refactoring the Codebase Separating Concerns: Models

Jolanta Dermody
PLUS
Jolanta Dermody
Courses Plus Student 13,118 Points

please help

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. i really stuck...

2 Answers

Myroslav Tkachenko
Myroslav Tkachenko
10,581 Points

You need to move the code that initializes an array with flavors, then in second step you need to simply return that array with return keyword:

function get_all_flavors() {
  $flavors = array(
    'flavor 1',
    'flavor 2'
  );

  return $flavors;
}

Hope this will help.

Paolo Scamardella
Paolo Scamardella
24,828 Points

Also, the 3rd step is to call get_all_flavors function, and since it returns an array, you have to assign it to the $flavors variable in the index.php file.