Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-stdlib/src/ArrayUtils.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 7a779792577d |
children |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
290 | 290 |
291 return $a; | 291 return $a; |
292 } | 292 } |
293 | 293 |
294 /** | 294 /** |
295 * Compatibility Method for array_filter on <5.6 systems | 295 * @deprecated Since 3.2.0; use the native array_filter methods |
296 * | 296 * |
297 * @param array $data | 297 * @param array $data |
298 * @param callable $callback | 298 * @param callable $callback |
299 * @param null|int $flag | 299 * @param null|int $flag |
300 * @return array | 300 * @return array |
301 * @throws Exception\InvalidArgumentException | |
301 */ | 302 */ |
302 public static function filter(array $data, $callback, $flag = null) | 303 public static function filter(array $data, $callback, $flag = null) |
303 { | 304 { |
304 if (! is_callable($callback)) { | 305 if (! is_callable($callback)) { |
305 throw new Exception\InvalidArgumentException(sprintf( | 306 throw new Exception\InvalidArgumentException(sprintf( |
306 'Second parameter of %s must be callable', | 307 'Second parameter of %s must be callable', |
307 __METHOD__ | 308 __METHOD__ |
308 )); | 309 )); |
309 } | 310 } |
310 | 311 |
311 if (version_compare(PHP_VERSION, '5.6.0') >= 0) { | 312 return array_filter($data, $callback, $flag); |
312 return array_filter($data, $callback, $flag); | |
313 } | |
314 | |
315 $output = []; | |
316 foreach ($data as $key => $value) { | |
317 $params = [$value]; | |
318 | |
319 if ($flag === static::ARRAY_FILTER_USE_BOTH) { | |
320 $params[] = $key; | |
321 } | |
322 | |
323 if ($flag === static::ARRAY_FILTER_USE_KEY) { | |
324 $params = [$key]; | |
325 } | |
326 | |
327 $response = call_user_func_array($callback, $params); | |
328 if ($response) { | |
329 $output[$key] = $value; | |
330 } | |
331 } | |
332 | |
333 return $output; | |
334 } | 313 } |
335 } | 314 } |