天天看點

處理無限極分類,多層分類

/**
     * 處理層級關系
     *
     * @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;
    }