1 | <?php |
||
16 | class Arr |
||
17 | { |
||
18 | /** |
||
19 | * If any of the provided values is in an array. |
||
20 | * This is a convenient function for constructs like in_array('val1', $a) || in_array('val2, $a) etc. |
||
21 | * |
||
22 | * @param array|string $anyValue Array of needles (will try any for a match) |
||
23 | * @param array $array Haystack array |
||
24 | * @return bool |
||
25 | */ |
||
26 | 2 | public static function anyIn($anyValue, $array) |
|
34 | |||
35 | /** |
||
36 | * If all of the provided values is in an array. |
||
37 | * This is a convenient function for constructs like in_array('val1', $a) && in_array('val2, $a) etc. |
||
38 | * |
||
39 | * @param array|mixed $allValues Array of needles (will try all for a match) |
||
40 | * @param array $array Haystack array |
||
41 | * @return bool |
||
42 | */ |
||
43 | 2 | public static function allIn($allValues, $array) |
|
62 | |||
63 | /** |
||
64 | * Get a new array with prefix applied to all values. |
||
65 | * |
||
66 | * @param array $array |
||
67 | * @param string $prefix |
||
68 | * @return array |
||
69 | */ |
||
70 | 1 | public static function valuesWithPrefix(array $array, $prefix) |
|
80 | |||
81 | /** |
||
82 | * Checks if all values in an array is empty (recursively). |
||
83 | * |
||
84 | * Doesn't consider other arrays with empty values non-empty as the normal |
||
85 | * empty() function does. |
||
86 | * |
||
87 | * @param array|mixed $input |
||
88 | * @return bool |
||
89 | */ |
||
90 | 2 | public static function allEmpty($input) |
|
104 | |||
105 | /** |
||
106 | * Filter associative array on keys, by provided keys, a callable or null (like array_filter, but for keys). |
||
107 | * |
||
108 | * @param array $inputArray |
||
109 | * @param array|callable|null $keysOrCallable |
||
110 | * @return array |
||
111 | */ |
||
112 | 3 | public static function filterKeys(array $inputArray, $keysOrCallable = null) |
|
126 | |||
127 | /** |
||
128 | * collect values from method calls from an array of objects. |
||
129 | * |
||
130 | * Ee.g. get all product names from an array of products. |
||
131 | * |
||
132 | * @param array $objectArray |
||
133 | * @param string $methodName |
||
134 | * @return array |
||
135 | */ |
||
136 | 1 | public static function objectsMethodValues(array $objectArray, $methodName) |
|
146 | |||
147 | /** |
||
148 | * Get a new array with all values cast to type. |
||
149 | * |
||
150 | * @param array $inputArray |
||
151 | * @param string $type |
||
152 | * @return array |
||
153 | */ |
||
154 | 1 | public static function valuesWithType(array $inputArray, $type) |
|
165 | |||
166 | /** |
||
167 | * Replaces values in array1 with values from array2 comparing keys and |
||
168 | * discarding keys that doesn't exist in array1 . |
||
169 | * |
||
170 | * @param array $array1 |
||
171 | * @param array $array2 |
||
172 | * @param bool $recursive |
||
173 | * @return array |
||
174 | */ |
||
175 | 3 | public static function replaceExisting(array $array1, array $array2, $recursive = false) |
|
189 | |||
190 | /** |
||
191 | * Sort by array. |
||
192 | * |
||
193 | * @param array $sortArray |
||
194 | * @param array $mapArray |
||
195 | * @return array |
||
196 | */ |
||
197 | 1 | public static function sortByArray(array $sortArray, array $mapArray) |
|
208 | |||
209 | /** |
||
210 | * @param array $array |
||
211 | * @param string $key |
||
212 | * @param mixed $default |
||
213 | * @return array |
||
214 | */ |
||
215 | 2 | public static function getValue(array $array, $key, $default = null) |
|
219 | } |
||
220 |