PHP递归生成树形数组

数据表结构

id   name  pid
     

 

 

private function tree($data,$p_id=0){
        foreach($data as $row){
            if($row['pid']==$p_id){
                $tmp = $this->tree($data,$row['id']);
                if($tmp){
                    $row['child']=$tmp;
                }else{
                    $row['leaf'] = true;
                }
                $tree[]=$row;                
            }
        }
        Return $tree;
    }

 

转载于:https://www.cnblogs.com/baby123/p/5382085.html

你可能感兴趣的:(PHP递归生成树形数组)