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 Sorting Array Items

Leigh Maher
Leigh Maher
21,830 Points

Why does the get_item_html have 2 parameters?

In the function that ouputs the html for the catalog pages, it's been set up to take 2 paramentes: $id and $item, but the $id is not referenced in the output code. I don't understand why there's 2 parameters being used here.

// Outputs the HTML for our catalog
function get_item_html($id, $item) {
  $output = "<li><a href='#'><img src='{$item['img']}' alt='{$item['title']}'>View Details</a></li>";
  return $output;
}
    foreach($categories as $id) {
        echo get_item_html ($id, $catalog[$id]);
      }

I've tested it without the $id parameter and it works fine.

Hi Leigh,

Yes!! It's not useful right now. Just go on till the end and you will find why she has included it.