组合成多维数组
public function cateattr($list,$pid=0){
$sa=[];
foreach ($list as $k=>$l){
if($l['pid']==$pid){
$l['children']=$this->cateattr($list,$l['id']);
$sa[]=$l;
}
}
return $sa;
}
public function unlimitedForLevel($cate,$html='--',$pid=0,$level=0){
//echo 1;
$arr=array();
foreach ($cate as $v){
if ($v['pid']==$pid){
//根据level来输出$html的个数
$v['level']=$level+1;
$v['html']=str_repeat($html, $level);
$arr[]=$v;
//递归合并
$arr=array_merge($arr,self::unlimitedForLevel($cate,$html,$v['id'],$level+1));
}
}
return $arr;
}
php 递归
于 2022-08-08 10:11:33 首次发布