递归菜单分组

public function getTree($list,$pid = 0,$level = 1)
    {
        $data = [];
        foreach ($list as $k => $v) {

            if ($v['pid'] == $pid) {
                $v['level'] = $level;
                $v['children'] = $this->getTree($list,$v['id'],($level + 1));
                $data[] = $v;
            }
            
        }

        return $data;
    }

仅有一条评论

添加新评论