无限极分类

     /**
     * 处理无限极分类 返回一个一维树性数组
     */
    static public function getTree($data,$pid=0,$level=0)
    {
        static $tree = [];
        foreach ($data as $k => $v) {
            if ($pid == $v['pid']) {
                $v['level'] = $level;
                $tree[] = $v;
                unset($data[$k]);
                self::getTree($data,$v['id'],$level + 1);
            }
        }
        return $tree;
    }

你可能感兴趣的:(无限极分类)