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 trialcalvindiguidig
Courses Plus Student 4,388 Pointsfunction 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
here is the code i just call this function into include.php file but it wont work
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi 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;
}
calvindiguidig
Courses Plus Student 4,388 PointsThanks for the help I didn't notice that thanks a lot
calvindiguidig
Courses Plus Student 4,388 Pointscalvindiguidig
Courses Plus Student 4,388 Pointssorry for my bad english