What happen if it is a very big array? One would try to save memory. The next example makes copies of parts of the array, but it should be not necessary, since the array is a global variable.
function arrayTraverse($key) {
global $someArray;
$keys = func_get_args();
$arrayPart = $someArray;
foreach ($keys as $key) {
$arrayPart = $arrayCopy[$key];
}
$value = $arrayPart;
return $value;
}
Usage example:
$someArray = [];
$someArray['aKey'] = [];
$someArray['aKey']['someOtherKey'] = [];
$someArray['aKey']['someOtherKey'][5] = [];
$someArray['aKey']['someOtherKey'][5]['value'] = 'hello';
echo arrayTraverse('aKey', 'someOtherKey', 5, 'value'); // hello