how to remove keys in subarray php

Solutions on MaxInterview for how to remove keys in subarray php by the best coders in the world

showing results for - "how to remove keys in subarray php"
Martina
08 Oct 2020
1print_r(deep_delete_keys($arr,'country'));
2
3function deep_delete_keys($arr, $keys) {
4    if (!is_array($keys)) $keys = array($keys);
5    $filteredArr = array_diff_key( $arr, array_flip( $keys ) );
6    foreach ($filteredArr as &$val) {
7        if (is_array($val)) {
8            $val = deep_delete_keys($val, $keys);
9        }
10    }
11    return $filteredArr;
12}