无限级分类
/** * Explanation:无限级分类 * Author: Abner * Time: 2021/1/10 17:33 * @param $data * @return array */ public static function getTree($data){ $items = []; foreach($data as $v){ $items[$v['category_id']] =$v; } $tree = []; foreach($items as $id => $item ){ if(isset($items[$item['pid']])) { $items[$item['pid']]['list'][] = &$items[$id]; }else{ $tree[]=&$items[$id]; } } return $tree; }