function generateTree($data){ $items = array(); foreach($data as $v){ $items[$v['auth_id']] = $v; } $tree = array(); foreach($items as $k => $item){ //用遍历每一项的pid来判别,判别$item这条数据有上级,且上级为id为pid的这条数据,当前的key应该为item这条数据的id if(isset($items[$item['auth_pid']])){ $items[$item['auth_pid']]['son'][] = &$items[$k]; }else{ $tree[] = &$items[$k]; } } return $tree; } id pid 116 100 200 116 234 200 $tree[0]=&$items[116] $items[$item['auth_pid']]['son'][] = &$items[$k]; $items[116]['son'][0]=&items[200] $items[200]['son'][0]=&items[234]
无限极分类