传进一个含id,pid,..的数组:
function catetree($arr,$id=0,$lev) {
$tree=array();
foreach ($arr as $v) {
if($v[‘pid‘]==$id) {
$v[‘lev‘]=$lev;
$tree=$v;
$tree=array_merge($tree,catetree($arr,$v[‘id‘],$lev+1));
}
}
return $tree;
}
时间: 2024-12-15 08:21:07