I just came across this code:
array_filter(array_map('intval', $array));
It seems to return all entries of $array converted to int where the number is > 0.
However, I can't see on the manual page that this is defined. It is supposed to return the array value if the callback function evaluates to true. But there isn't any callback function defined here.
Confusing is also that the callback function is optional on the manual page.
Removes empty or equivalent values from array:
$entry = array(
0 => 'foo',
1 => false,
2 => -1,
3 => null,
4 => '',
5 => 0
);
print_r(array_filter($entry));
Result
Array
(
[0] => foo
[2] => -1
)
See the original documentation from the manual: Example #2 array_filter() without callback
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With