PHP Programing language

adplus-dvertising
array_filter() Functions in PHP
Previous Home Next
adplus-dvertising

array_filter()

The array_filter() function filters the values of an array using a callback function. If the callback function returns true, the current value from input is returned into the result array. Array keys are preserved.

Syntax:
array_filter(array,callbackfunction);

Example:

<?php
function test_even($var)
{
return($var & 2);
}
$array1=array("a","b",2,4,6);
print_r(array_filter($array1,"test_even"));
?>

Output:

Array ( [2] => 2 [4] => 6 )

Previous Home Next