1 | <?php |
||
8 | class ArrayUtility extends AbstractUtility |
||
9 | { |
||
10 | /** |
||
11 | * Filter an array based on $keepKeys. |
||
12 | * |
||
13 | * @param array $toFilter |
||
14 | * @param array $keepKeys Includes the keys that need to be kept in $toFilter array |
||
15 | * |
||
16 | * @return array |
||
17 | */ |
||
18 | 29 | public function filterArray(array $toFilter, array $keepKeys) |
|
22 | |||
23 | /** |
||
24 | * Check if key is present in $search array and has got a value only if the value is string. |
||
25 | * |
||
26 | * @param $key |
||
27 | * @param array $search |
||
28 | * |
||
29 | * @return bool |
||
30 | */ |
||
31 | 31 | public function arrayKeyValueExists(string $key, array $search): bool |
|
43 | |||
44 | /** |
||
45 | * Set a value in a nested array based on path. |
||
46 | * |
||
47 | * @param array $array The array to modify |
||
48 | * @param array $path The path in the array |
||
49 | * @param mixed $value The value to set |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | 24 | public function setNestedArrayValue(array &$array, array $path, &$value) |
|
62 | |||
63 | /** |
||
64 | * Get a value in a nested array based on path |
||
65 | * See https://stackoverflow.com/a/9628276/419887. |
||
66 | * |
||
67 | * @param array $array The array to modify |
||
68 | * @param array $path The path in the array |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | 1 | public function getNestedArrayValue(array &$array, array $path) |
|
81 | |||
82 | /** |
||
83 | * @param $array |
||
84 | * |
||
85 | * @return mixed |
||
86 | */ |
||
87 | 6 | public function sortArrayByLength(array $array) |
|
95 | |||
96 | /** |
||
97 | * Find the key for the max positive value. |
||
98 | * |
||
99 | * @param $array |
||
100 | * |
||
101 | * @return mixed |
||
102 | */ |
||
103 | 4 | public function maxPositiveValueKey(array $array) |
|
111 | } |
||
112 |