Home > PHP > Function > Arrays > array_filter()

array_filter()

array_filter - Filters elements of an array using a callback function

Syntax

array array_filter (array $input, callback $callback)

Arguments

  • input - The array to iterate over
  • callback - The callback function to use If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed.

Description

Iterates over each value in the input array passing them to the callback function. If the callback function returns true, the current value from input is returned into the result array. Array keys are preserved.

Version

PHP 4.0.6, 5

Return value

Returns the filtered array.