X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP array_filter() Function

PHP Array Reference PHP Array Reference

Example

Fill an array with values, specifying keys:

<?php
function test_odd($var)
{
return($var & 1);
}

$a1=array("a","b",2,3,4);
print_r(array_filter($a1,"test_odd"));
?>

Run example »

Definition and Usage

The array_filter() function filters the values of an array using a callback function.

This function passes each value of the input array 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.


Syntax

array_filter(array,callbackfunction);

Parameter Description
array Required. Specifies the array to filter
callbackfunction Required. Specifies the callback function to use

Technical Details

Return Value: Returns the filtered array
PHP Version: 4.0.6+


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook