数组的多维关联数组

keelerjr12

为什么这不会推迟或添加到最后?

这两种方法我都试过了。

class Router
{
    public function __construct()
    {
        $this->routes['GET'] = [];
        $this->routes['POST'] = [];
    }

    public function handle($request)
    {
        echo count($this->routes['GET']) . "<br/>";  // outputs '0'.. why??
    }

    protected function addRoute($methods, $uri, $action)
    {
        #array_push($this->routes['GET'], 'TEST'); // Tried this as well
        $this->routes['GET'][] = 'test';
        echo count($this->routes['GET']) . "<br/>";  // outputs '1'
    }

    private $routes = [];
}

在我执行addRoute然后检查$this->routes[$methods]using count()in的大小后handle($request),它显示为 0。

keelerjr12

解决了...

啊,可怕的单身人士抓住了我。出于某种原因,没有使用相同的对象。我已经从我的应用程序中删除了单例模式。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章