Forum Moderators: coopster
The array depth is unknown, can be a n-dimensional array, but once it gets to the value, it needs to compare it to the original array it was duplicated from. It follows the same key path, eg:
$original_array['test'][1]['stuff']
But I can't go
$keys = explode($key_list);
$original_array[$keys[0]][$keys[1]][$keys[2]];
Because it might only need $keys[0] or could go to $keys[n]
How do I go about that?
I tried stuff like:
$key_list = "[test][1][stuff]";
$original_array[$key_list];
and
$original_array{$key_list};
But as expected, that failed ( I was really hoping )
Any ideas?
Thanks
function &get_array_by_key_array(&$array, $key_array = array()) {
$temp_array =& $array;
foreach ($key_array as $key => $value) {
if (isset($temp_array[$value])) {
$temp_array =& $temp_array[$value];
} else {
return null;
}
}
return $temp_array;
}
which works great.
But is there any language construct that will let me do it without any extra function, or just a better way?