function get_arr_value_by_path($array, $path) { $found_values = array(); $curr_node = $array; $path_elems = explode(".", $path); $remaining_path = $path; foreach ($path_elems as $elem) { $remaining_path = substr($remaining_path, strlen($elem) + 1); if ($elem == "*") { foreach ($curr_node as $arr_item) { $values = get_arr_value_by_path($arr_item, $remaining_path); if (is_array($values)) { $found_values = array_merge($found_values, $values); } } break; } if (isset($curr_node[$elem])) { $curr_node = $curr_node[$elem]; if (!is_array($curr_node) or $remaining_path == "") { $found_values[] = $curr_node; } } else { return NULL; } } return $found_values; }
function get_arr_value_by_path($array, $path) { $found_values = array(); $curr_node = $array; $path_elems = explode(".", $path); $remaining_path = $path; foreach ($path_elems as $elem) { $remaining_path = substr($remaining_path, strlen($elem) + 1); // echo $remaining_path."\n"; if ($elem == "*") { foreach ($curr_node as $arr_item) { // var_dump($arr_item); // echo "Rem path: " . $remaining_path."\n"; $values = get_arr_value_by_path($arr_item, $remaining_path); // echo "Values:\n"; // var_dump($values); // echo "Found values:\n"; // var_dump($found_values); if (is_array($values)) { $found_values = array_merge($found_values, $values); } } break; } if (isset($curr_node[$elem])) { $curr_node = $curr_node[$elem]; if (!is_array($curr_node) or $remaining_path == "") { $found_values[] = $curr_node; } } else { return NULL; } } // echo "Returning:\n"; // var_dump($found_values); return $found_values; }