<?PHP
function eachCategory($cates,$lv=1){
foreach($cates as $v){
echo $v['name'];
echo str_repeat(' >> ',$lv);
if($v['child']){
$this->eachCategory($v['child'],$lv+1);
}
}
}
function category(&$cates,$pid=0){
$tree = array();
foreach($cates as $v){
if($v['parent_id'] == $pid){
$v['child'] = $this->category($cates,$v['cat_id']);
$tree[] = $v;
}
}
return $tree;
}