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 Creating the Display Function

issue Using varies in funciton.php

Why use two varies instead for one vary because i saw don't use $id

<?php function get_item_html($id,$item){

$output = "<li><a href='#'><img src='" .$item["img"]."' alt='" .$item["title"]."' />" ."<p>View Detials</p>" ."</a></li>"; return $output;

}

1 Answer

Damien Watson
Damien Watson
27,419 Points

Hi,

You are correct in saying you don't need to pass the $id because you are not using it. I could be wrong but I would say in this instance she is including it for future use, or incase she needs to reference it down the track.

This would allow you to do something like set the id to the list item. Meaning that clicking the item would give you access to the parents id. Or putting it on the anchor tag even.

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