迷茫2017-06-05 11:10:01
使用递归函数,不过我写这种方法空间复杂度没有得到优化,忘记以前的写法了
private function getTreeList($data, $pid = 0)
{
$resultarr = array();
foreach ($data as $teamdata) {
if ($teamdata['pid'] == $pid) {
$team_data = $teamdata;
$children_data = $this->getTreeList($data, $teamdata['id']);
$team_data['children'] = $children_data;
$resultarr[] = $team_data;
}
}
return $resultarr;
}