array_reject() as counterpart of array_filter()
| From: | David Rodrigues | Date: | Sun, 30 Aug 2020 14:38:36 +0000 |
| Subject: | array_reject() as counterpart of array_filter() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-111722@lists.php.net to get a copy of this message | ||
Currently we have array_filter(), but sometimes we need an inverse function
like array_reject().
array_reject('is_null', [ 1, 2, null, 3 ]); // [ 1, 2, 3 ]
It could be easily implemented with:
function array_reverse($fn, $arr) { return array_filter(fn($item) =>
!$fn($item), $arr); }
Anyway, I think that It should be implemented by core, once that we have
array_filter().