All pastes #386815 Raw Edit

avoid global $liste?

public php v1 · immutable
·published 2007-03-08 22:10 UTC
rendered paste body
/** * 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 depthsfunction 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;}