Filters the collection using the given callback.
Use array_values()
, array_diff()
and array_filter()
to filter $items
based on $func
.
代码实现
function reject($items, $func)
{
return array_values(array_diff($items, array_filter($items, $func)));
}
使用样例
reject(['Apple', 'Pear', 'Kiwi', 'Banana'], function ($item) {
return strlen($item) > 4;
}); // ['Pear', 'Kiwi']