public function get_tree(){ //递归遍历数组; $items=[]; foreach($position as $k=>$v){ $items[$v['id']]=$v; } $tree=[]; foreach($items as $k=>$v){ if($v['pid'] && isset($items[$v['pid']])){ $items[$v['pid']]['children'][]=&$items[$k]; }else{ $items[$k]['cid']=$company_id; $tree[]=&$items[$k]; } } return $tree; }