Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Enhancing a Simple PHP Application Refactoring the Codebase Separating Concerns: Models

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,413 Points

function get_all_flavors() task 3 of 3

..just when I thought that I had made it through this task without stumbling.....

Stuck.....

Am I close?

Thanks:-

index.php
<?php

// ==== INCLUDE MODEL FILE ====
require_once('flavors.php');



?>

<h1>Ye Olde Ice Cream Shoppe</h1>

<p>Here&rsquo;s a full list of our ice cream flavors.</p>

<ul>
<?php
function get_all_flavors(){
  $flavors = get_all_flavors;


  }
  return = $flavors;

    $list_html = "";
    foreach($flavors as $flavor) {
        $list_html = $list_html . "<li>";
        $list_html = $list_html . $flavor;
        $list_html = $list_html . "</li>";
    }
    echo $list_html;

?>
</ul>
flavors.php
<?php
function get_all_flavors(){
  $flavors = array(
        "Jalapeno So Spicy",
        "Avocado Chocolate",
        "Peppermint",
        "Vanilla",
        "Cake Batter",
        "Cookie Dough"
    );
  return $flavors;



}
// MODEL FILE






?>

1 Answer

Ben Lockett
Ben Lockett
22,419 Points

Hi Juliette,

I cannot see the question but I'm guessing you are meant to call the get_all_flavours function.

function get_all_flavors(){ $flavors = get_all_flavors;

} return = $flavors;

The above code is incorrect. you need to call the get_all_flavors function with "get_all_flavors()" but you need to pass this to the $flavors variable with the "=". I don't want to write the answer out as its not the Treehouse way but hopefully this will help.

Ben

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,413 Points

Thanks Ben!

This was the question and this is what worked in the end (thanks to you):

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.

<?php function get_all_flavors(){ $flavors = get_all_flavors; $flavors = array( "Jalapeno So Spicy", "Avocado Chocolate", "Peppermint", "Vanilla", "Cake Batter", "Cookie Dough" );

return $flavors; } // MODEL FILE ?>