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


I don't see the use of 2 parameters in this function

$random = array_rand($catalog, 4);
foreach($random as $id) {
   echo get_item_html($id, $catalog[$id]);

Why would we need the first parameter in that function if we've already used the value for $id on $catalog[$id], and we're not doing anything to first parameter alone, why is that?

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

As you see we don't use the first parameter here in any way, so why do we even need 2 parameters?

1 Answer

Never Mind!! I found the answer I was looking for here, in case someone is looking for the same