Completed
Push — master ( de5280...ddb179 )
by Dimas
09:43
created

array_unique_recursive()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * ```php
5
 * array_filter_recursive(['password'=>'secret_password', 'username'=>'any'], ['password']); //will return without password
6
 * ```
7
 * Array filter recursive
8
 *
9
 * @param array $array
10
 * @param array $filterdata
11
 * @return array
12
 */
13
function array_filter_recursive(array $array, array $filterdata)
14
{
15
  if (\ArrayHelper\helper::isSequent($array)) {
16
    return array_map(function ($single) use ($filterdata) {
17
      foreach ($filterdata as $filter) {
18
        if (isset($single[$filter])) {
19
          unset($single[$filter]);
20
        }
21
      }
22
      return $single;
23
    }, $array);
24
  }
25
}
26
27
/**
28
 * Array unique recursive.
29
 *
30
 * @return array
31
 */
32
function array_unique_recursive(array $array)
33
{
34
  $array = array_unique($array, SORT_REGULAR);
35
36
  foreach ($array as $key => $elem) {
37
    if (is_array($elem)) {
38
      $array[$key] = array_unique_recursive($elem);
39
    }
40
  }
41
42
  return $array;
43
}
44
45
/**
46
 * Check multiple array keys exists
47
 *
48
 * @param array $keys
49
 * @param array $arr
50
 * @return bool
51
 */
52
function array_keys_exists(array $keys, array $arr)
53
{
54
  return !array_diff_key(array_flip($keys), $arr);
55
}
56