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()
.
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()
.
Any boolean function can be inverted with a simple ! in a short closure. I don't really see a need to do that in C.
--Larry Garfield