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

Pol Ribas Pibernat
Pol Ribas Pibernat
8,952 Points

Blank images & data

Hi,

The array_category var_dumps the following...

array(4) { [0]=> int(102) [1]=> int(104) [2]=> int(101) [3]=> int(103) }

And when entering to the get_item_html... it doesn't find anything when trying to access $item['img'].

My code: functions.php: function array_category($catalog, $category) { if ($category==null) { return array_keys($catalog); } else { $output = array();

foreach ($catalog as $id => $item) {
  if (strtolower($category) == strtolower($item['category'])) {
    $sort = $item['title'];
    $sort = ltrim($sort, "The ");
    $sort = ltrim($sort, "A ");
    $sort = ltrim($sort, "An ");
    $output[$id] = $sort;
  }
}
asort($output);
return array_keys($output);

} }

catalog.php <div class="section catalog page"> <div class="wrapper"> <h1><?php echo $pageTitle; ?></h1> <ul class="items"> <?php $catalog = array_category($catalog, $section); foreach ($catalog as $id => $item) { echo get_item_html($id, $item); }

  ?>
</ul>

</div> </div>

What do I have wrong?

1 Answer

Hi there Pol!

Can you show us php get_item_html() function?

Best regards.