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

where is the data for the variable $category coming from?

https://teamtreehouse.com/library/displaying-categories

function array_category($catalog,$category){ $output = array();

        foreach($catalog as $id => $item){
        if (strtolower($category) == strtolower($item["category"])){
                        $output[] = $id;
              }
        }
        return $output;

}

In the video when Alena is first setting up the function array_category($catalog,$category)

she passes through a variable name $category , where is this data coming from so that it will match the $item["category"] from the catalog array to get added to the array output, inside of the foreach loop? I am confused because I see that the $category variable isn't used on the index.php or catalog.php page at all, its only mentioned in the functions.php page.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Remember that a parameter is a temporary variable for that function. She calls the function in catalog.php and sends in the $catalog and the $section. The $section is sent in to match the $category parameter. You can see this in 4:08 of the video on line 31.

Hope this helps! :sparkles:

Oh, now I see, I thought it would be the same as the $section variable, but I wasn't sure since it on the functions.php page, it make sense now, thanks , Jennifer.