I am trying to get a part of an array but when I do the key does not carry over with it.
for instance if I have:
Array
(
[default_route] => Array
(
[path] => /
[controller] => IndexController
[action] => indexAction
)
[hello_route] => Array
(
[path] => /hello
[controller] => HelloController
[action] => helloAction
)
)
and I would like to get just the array with the index of default_route
it returns that array but the key is removed so the result is:
Array <- no more key string...
(
[path] => /
[controller] => IndexController
[action] => indexAction
)
I tried array_intersect_key($routes, array_flip(array($key)));
but that places a single array into another array which is pointless because there will never be more than one at a time. I don't want a 2 dimensional array with one element in it, I would like just the array with the correct key value.
implementation:
foreach ($routes as $key => $val)
{
// $routeArray = array_intersect_key($routes, array_flip(array($key)));
// would put whats above but that is what creates the unnecessary two dimensional array
$routeObj = new Route($routes[$key]);
$newRouteObjs[] = $routeObj;
}
return $newRouteObjs;
and here is the constructor for the route. I was just going to take the array and break it apart.
public function __construct(array $route)
{
$this->name = key($route);
$this->path = $route['path'];
$this->controller = $route['controller'];
$this->action = $route['action'];
}
I simply want to pull out the section and keep the key string. I have a feeling this is easy and I am just missing something.