array_filter in PHP

Syntax of array_filter

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:

Example of array_filter in PHP

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

Leave a Comment