无限级分类

/**
     * 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;
    }

 

posted @ 2021-01-10 17:34  Abner3721  阅读(54)  评论(0编辑  收藏  举报