jdog jdog - 1 year ago 64
PHP Question

what does array_filter with no callback do?

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 is no callback function defined here.

Confusing is also that the callback function is optional on the manual page: http://php.net/manual/en/function.array-filter.php

Answer Source

Removes empty or equivalent values from array:

Example #2 array_filter() without callback

   $entry = array(
                 0 => 'foo',
                 1 => false,
                 2 => -1,
                 3 => null,
                 4 => ''



    [0] => foo
    [2] => -1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download