Milos Stankovic
Milos Stankovic
15,691 Points

Function get_item_html works fine without $id argument

I removed $id argument from get_item_html($item):

function get_item_html($item) {
    $output = "<li><a href='#'><img src='". $item['img'] ."' alt='" . $item['title'] ."' /><p>View details</p></a></li>";
    return $output;

Also in index.php and catalog.php files that are using this function:

echo get_item_html($catalog[$id]);

The program works fine without it, so I am wondering why it needs to be there?


3 Answers

Hi Milos,

The id is needed for the href attribute on the link. It's currently # as a placeholder but really needs to link to the details.php page.

Updating this link was omitted from the videos but the video linked to below contains an update in the teacher's notes showing how to update the link and why we need the $id.

Milos Stankovic
Milos Stankovic
15,691 Points


Many thanks! Now it makes sense, I updated my product details links.

Thanks again

Alex Forseth
Alex Forseth
8,016 Points

Why is this information not put in the teachers note in the "random fun with arrays" section? Or in an earlier section?