php--无限极分类

效果图:

 

代码:

//无限极分类  遍历前台职位
    public function getCategory($cate,$pid=0)
    {

        $child = array();

        foreach($cate as $v){
            if($v['parent_id'] == $pid)
            {
                $child[] = $v;
            }
        }

        if(empty($child))
        {
            return null;
        }

        //取出子集
        foreach($child as $key=>$v)
        {
            $new_child = $this->getCategory($cate,$v['cate_id']);

            if($new_child)
            {

                $child[$key]['child']=$new_child;

            }
        }

        return $child;

    }

posted @ 2016-03-29 19:30  不解凡忧  Views(178)  Comments(0Edit  收藏  举报