Given your definition of $valKeys
and $xyz
, I think a recursive function is most appropriate:
function multi_array_key_get($multi_dim_array, $key_array, $pos=0) {
$key_count = count($key_array)
if ($pos < $key_count) {
return multi_array_key_get($multi_dim_array[$key_array[$pos]], $pos+1);
}
elseif ($pos == $key_count) {
return $multi_dim_array[$key_array[$pos]];
}
}
Call the function:
multi_array_key_get($xyz, $valKeys);
This is a bit of a draft function - you should add code to handle the cases where the array does not contain the key.
Setting the values using this function would require you to adjust the function with an additional argument- the value to set.