Hi,
I have built an array of category id's that are used to filter product results within an ecommerce system. All categories also have a parent_id, stored within mysql. I need to loop through the array and build a list that will present the nesting of the categories as the current array stores the id's only.
Initially i had an array of category results, i have extended this by adding all parent categories of this that will be required to show the nesting.
$cats_store = array(); # stores all cats and parent used
$cats_with_results = array(); # stores cats with actual results to filter with
foreach($cat_results as $key=>$val)
{
$cats = getcatstruc($key); # returns ids of all parents (including parent id of 0 for top level cats)
foreach($cats as $val) # loop through parent cats
{
if(!in_array($val,$cats_store)) $cats_store[] = $val; # add parent cats to array
}
if(!in_array($key,$cats_store)) $cats_store[] = $key; # add results cats to array
$cats_with_results[] = $key; # store cats with results
}
I'm guessing i probably need to put together a recursive function to loop through, maybe i should also add each parent id to the $cats_store array. Would really appreciate any help/ideas on this. Thanks.