84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
How to perform unlimited classification based on id and pid
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
Use a recursive function, but the space complexity of this method was not optimized. I forgot the previous way of writing it
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; }
Use recursion to loop out an array
public function gettree($items, $parent_id = 'parent_id', $id = 'id'){ $tree = array(); //格式化好的树 if(empty($items)){ return $tree; } foreach ($items as $item){ if (isset($items[$item[$parent_id]])){ $items[$item[$parent_id]]['son'][] = &$items[$item[$id]]; }else{ $tree[] = &$items[$item[$id]]; } } return $tree; }
Use a recursive function, but the space complexity of this method was not optimized. I forgot the previous way of writing it
Use recursion to loop out an array