递归处理层级展示

 1    public static function treeLevels($data,$pid="0",$html="--",$level=0){
 2         static $arr=[];
 3         foreach ($data as $key=>$val){
 4             if ($val['pid']==$pid){
 5                 $val['html']=str_repeat($html,$level*2);
 6                 $arr[]=$val;
 7                 //递归 自己调用自己
 8                 self::treeLevels($data,$val['id'],'--',$level+1);
 9             }
10         }
11         return $arr;
12 
13     }

 

posted @ 2021-01-28 23:28  Conqueror·  阅读(134)  评论(0编辑  收藏  举报