处理无限极分类,多层分类

    /**
     * 处理层级关系
     *
     * @param $data
     * @param int $pid
     * @param int $level
     * @return array
     */
    protected function doneCateLevel($data,$noCat=0,$pid=0,$level=1)
    {       
        static $catList = [];
        if(is_array($data) && count($data)>0)
        {
            foreach ($data as $key=>$val)
            {
                if($val['pid'] == $pid && $val['id'] != $noCat)
                {
                    $val['level'] = $level;
                    $catList[] = $val;                  
                    $this->doneCateLevel($data,$noCat,$val['id'],$level+1);
                }
            }
        }
        return $catList;
    }

 

你可能感兴趣的:(点石成金,PHP)