Name

array_filter

Synopsis

array array_filter(array array, mixed callback)

Creates an array containing all values from the original array for which the given callback function returns true. If the input array is an associative array, the keys are preserved. For example:

function isBig($inValue) {
  return($inValue > 10);
}
  
$array = array(7, 8, 9, 10, 11, 12, 13, 14);
$new_array  = array_filter($array, "isBig"); // contains (11, 12, 13, 14)

Get Programming PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.