One possible (recursive) approach:
function access_array(array $target, array $keys) {
$target = $target[ array_shift($keys) ];
return $keys ? access_array($target, $keys) : $target;
}
Another possible (iterative) approach:
function access_array(array $target, array $keys) {
foreach ($keys as $k) {
$target = $target[$k];
}
return $target;
}
P.S. I can't really say it better than @MarkB did:
PHP is a toolbox. it contains screwdrivers, hammers, maybe a measuring
tape and a pencil. You're expecting it to contain a fully developed
house, complete with plumbing and electrical wiring for EVERY possible
thing you want it to do. Instead of flailing around looking for a can
opener that will cook your thanksgiving dinner and help your kids get
into college, you should learn how to use the basic tools PHP does
provide to BUILD that all-in-one tool.
$my_array['a']['b']).