1
なぜこれをプッシュバックまたはエンドに追加しないのですか?配列の多次元連想配列
私は両方の方法を試しました。
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
を実行し、その後handle($request)
でcount()
を使用して$this->routes[$methods]
のサイズを確認した後、それが解決0
'$ methods'には何がありますか、これはどのように呼びますか?あなたはどこで 'count()'しますか? – colburton
@colburton、fixed。 $メソッドはここでは役に立たない。 – keelerjr12
'addRoute()'や 'handle()'はまだ呼び出せません。同じオブジェクトを使用していない可能性が最も高いです。 – colburton