php--无限极分类

时间:2023-02-06 18:56:37

效果图:

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;

}