递归处理层级展示

 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     }
原文地址:https://www.cnblogs.com/cyxng/p/14342579.html