传进一个含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-10-13 12:25:10