Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions src/ArrayUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ public static function merge(array $a, array $b, $preserveNumericKeys = false)
}

/**
* Compatibility Method for array_filter on <5.6 systems
* @deprecated Since 3.2.0; use the native array_filter methods
*
* @param array $data
* @param callable $callback
* @param null|int $flag
* @return array
* @throws Exception\InvalidArgumentException
*/
public static function filter(array $data, $callback, $flag = null)
{
Expand All @@ -308,28 +309,6 @@ public static function filter(array $data, $callback, $flag = null)
));
}

if (version_compare(PHP_VERSION, '5.6.0') >= 0) {
return array_filter($data, $callback, $flag);
}

$output = [];
foreach ($data as $key => $value) {
$params = [$value];

if ($flag === static::ARRAY_FILTER_USE_BOTH) {
$params[] = $key;
}

if ($flag === static::ARRAY_FILTER_USE_KEY) {
$params = [$key];
}

$response = call_user_func_array($callback, $params);
if ($response) {
$output[$key] = $value;
}
}

return $output;
return array_filter($data, $callback, $flag);
}
}