Why is that of the array in a loop is selected, only the first element, why?

The array looks like this:
2803d2cc49e3488486eee68487d7e9ab.png
When I walk through it in a loop and trying to return the values (all three elements) using var_dump, it returns only this:
d0cb07d600444f52a53f7fdec0528a93.png
What am I doing wrong? It's supposed to work

foreach($array as $val) {
var_dump($val);
}
June 26th 19 at 14:23
2 answers
June 26th 19 at 14:25
Somewhere correctly you have an array set.
Make before the loop var_dump($array);

I have prints all three values:
spoiler
<?php
$test=array (
 array (
"url"=-->"/",
"controller"=>"Task",
"action"=>"tasks",
"params"=>NULL,
),
 array (
"url"=>"/add",
"controller"=>"Task",
"action"=>"create",
"params"=>NULL,
),
 array (
"url"=>"/delete",
"controller"=>"Task",
"action"=>"delete",
"params"=>NULL,
),
);
foreach ($test as $value)
var_dump($value);
?>

$ php a.php
array(4) {
["url"]=>
 string(1) "/"
["controller"]=>
 string(4) "Task"
["action"]=>
 string(5) "tasks"
[params]=>
NULL
}
array(4) {
["url"]=>
 string(4) "/add"
["controller"]=>
 string(4) "Task"
["action"]=>
 string(6) "create"
[params]=>
NULL
}
array(4) {
["url"]=>
 string(7) "/delete"
["controller"]=>
 string(4) "Task"
["action"]=>
 string(6) "delete"
[params]=>
NULL
}
protected $routes = array();

 public function add($url, $controller, $action, $params = NULL)
{
 $route = array("url" => $url, "controller" => $controller, "action" => $action, params => $params);
 array_push($this->routes, $route);
 }
- Alexander.Schmeler90 commented on June 26th 19 at 14:28
the whole code so let's - Candace_Bogisich commented on June 26th 19 at 14:31
June 26th 19 at 14:27
foreach($array as $val[0]) {
var_dump($val);
}

Find more questions by tags PHP