/** * Recursive function which returns a flat list of childrens of a specific category /** * @param $cid : The ID of the category to travel through * @param $types : A flat list of all categories, indexed by their IDs(generated on first pass) * @param $treetypes : A list of all categories, grouped by depth and indexed by their parent's ID(generated on first pass) * @param $level : An increment parameter that give an account of the current depth */ $liste=array(); // Global variable to collect children categories encountered during crossing depths function childrenlist ($cid, $types=array(), $treetypes=array(), $level=0 ) { global $database, $liste; // Let's generate(only on first pass) $types and $treetypes: if( empty($treetypes) || empty($types) ) { //useless to show you } array_push($liste, $types[$cid]->name); if (!@$treetypes[$cid]){ // Stoppage condition! return $liste; } else { foreach ($treetypes[$cid] as $treetype) { childrenlist($treetype->id, $types, $treetypes, $level+1); } } return $liste; }