ARRAY_FILTER
Filters elements of an array using a callback function
SYNTAX
array_filter ( array $array [, callable $callback [, int $flag = 0 ]] ) : array
PARAMETERS
array
The array to iterate over.
callback
The callback function to use. If no callback is supplied, all entries of array equal to FALSE will be removed.
flag
Flag determining what arguments are sent to callback:
0 | pass value as the only argument to callback |
ARRAY_FILTER_USE_KEY | pass key as the only argument to callback |
ARRAY_FILTER_USE_BOTH | pass both value and key as arguments to callback |
RETURN
Returns the filtered array.
EXAMPLES
ARRAY
Array
(
[6] => 0.0
[7] => abc
)
CALLBACK | TRUE
Array
(
[6] => 0.0
[7] => abc
)
CALLBACK | EVEN
Array
(
[a] => 0
[c] => 2
[e] => 4
)
FLAG | 0
array(1) {
["e"]=>
int(4)
}
FLAG | ARRAY_FILTER_USE_KEY
array(1) {
["c"]=>
int(2)
}
FLAG | ARRAY_FILTER_USE_BOTH
array(2) {
["c"]=>
int(2)
["e"]=>
int(4)
}