Access Multidimensional Array element with out knowing parent elements

后端 未结 4 935
忘了有多久
忘了有多久 2021-01-16 22:25

I have function that returns the following multidimensional array. I don\'t have control of how the array is formed. Im trying to access the \'Result\' elements. This issue

4条回答
  •  悲&欢浪女
    2021-01-16 23:06

    Edit: array_column won't actually work in this case. You could search through each level, recursively, until you find the given key. Something like:

    function find_key_value($array, $search_key) {
        if (isset($array[$search_key])) return $array[$search_key];
        $found = false;
        foreach ($array as $key=>$value) {
             if (is_array($value)) $found = find_key_value($value, $search_key);
             if ($found) return $found; 
        }
        return false;
    }
    

提交回复
热议问题