不使用递归实现无限极分类

1])->toArray();
        $list = self::getTree($list);
        if(!empty($cate_name)){
            foreach ($list as $item){
                if($item['name']=='漫画'){
                    $list = $item;
                }
            }
        }
        $cate['book_type'] = $list;
        $cate['lianzai'] = $liazai_cate;
        $cate['pay_type'] = $pay_cate;
        return $cate;
    }

   private static function getTree($list){
        $tree = [];
        $list = array_column($list,null,'id');
        foreach($list as $val){
            if(isset($list[$val['parent_id']]))
                $list[$val['parent_id']]['son'][] = &$list[$val['id']];
            else
                $tree[] =  &$list[$val['id']];
        }
        return $tree;
    }
}

你可能感兴趣的:(php)