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 Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying Categories

Jackson Hyland
Jackson Hyland
4,920 Points

Displaying Categories - my pages won't display any content after following the video and checking against her code.

After carefully checking my code against Alena's, i am still not getting the same results. I've had no problems so far and my code has not given me any trouble so far. I'll copy what i input during this video and pehaps someone could tell me what iv'e done wrong?

any clarification just ask.

FIRST CODE

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

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

        }
    }

    return $output;
}

SECOND CODE:

  $categories = array_category($catalog,$section);
            foreach($categories as $id) {
                echo get_item_html($id,$catalog[$id]);
            }

at this point, she goes back to the browser to show how each page will only display its appropriate category.

Any help would be much appreciated. :)

fixed code formatting

1 Answer

Hi Jackson,

You should only have 1 return statement at the end. You accidentally put in another one on the 2nd line of your function code. This would cause the function to return right there and it would never make it to the foreach loop.

Also, inside your if statement you have $ouput[] = $id; You have a typo there with the $output variable.

Jackson Hyland
Jackson Hyland
4,920 Points

great thanks alot! always those small details i tend to miss.