时间:2021-07-01 10:21:17 帮助过:4人阅读
Array
(
[0] => Array
(
[id] => 3
[fid] => 0
[name] => 333
[son] => Array
(
[0] => Array
(
[id] => 2
[fid] => 3
[name] => 2_3
[son] => Array
(
[0] => Array
(
[id] => 4
[fid] => 2
[name] => 2_4
)
)
)
[1] => Array
(
[id] => 5
[fid] => 3
[name] => 2_3
)
)
)
[1] => Array
(
[id] => 1
[fid] => 0
[name] => 111
)
)
function tree_add_level($tree){
foreach($tree as &$val){
if(!isset($val['_level'])){
$val['_level']=0;//顶层为0
}
if(isset($val['son'])){
$val['son']['_level']=$val['_level']+1; //下级加1
tree_add_level($val['son']);
}
}
return $tree;
}