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 Displaying Categories

function array_category() won't work

i don't know what's wrong to my code i just follow the tutorial of alena holligan using array to display specific category using array_category() function but when i use it into include.php file to display it won't throw any error but instead it doesn't show any images i think there is something wrong into array

https://w.trhou.se/c1pkv36jo2

here is the code i just call this function into include.php file but it wont work

sorry for my bad english

1 Answer

Hi Calvin,

Near the top of catalog.php you have a right parenthesis after the 2nd include.

<?php 
include("inc/data.php");
include)("inc/function.php"); // delete the ) after include

In your array_category function you have another syntax error. In the foreach loop you have a comma that doesn't belong.

<?php
function array_category($catalog, $category){
  $output = array();
  foreach($catalog, as $id =>$item){ // remove the comma after $catalog
      if(strtolower($category) == strtolower($item["category"])){
          $output[] = $id;
      }
  }
  return $output;
}

Thanks for the help I didn't notice that thanks a lot