PHP處理資料 樹形結構 全部子節點為根節點的一個子陣列
阿新 • • 發佈:2018-12-07
public static function resursive_make_tree($list,$pk='Fid',$pid='parent_id',$child='_child',$root=0) { $tree = []; foreach ($list as $key=>$val){ if($val[$pid] == $root ){ unset($list[$key]); if(!empty($list)){ $child = self::resursive_make_tree($list,$pk,$pid,$child,$val[$pk]); if(!empty($child)){ $val['_child'] = $child; } } $tree[] = $val; } } return $tree; }