array_filter
Use callback function to filter units in array
array_filter()
function uses a callback function to filter values in an array.
This function passes each key value in the input array to the callback function. If the callback function returns true, the current key value in the input array is returned to the result array. The array key names remain unchanged.
Use callback functions to filter elements in an array:
<?php function test_odd ( $var ) { return ( $var & 1 ) ; } $a1 = array ( "a" , "b" , 2 , 3 , 4 ) ; print_r ( array_filter ( $a1 , "test_odd" ) ) ; ?>
Try it yourself
array_filter ( array , callbackfunction ) ;
parameter | describe |
---|---|
array | Required. Specifies the array to be filtered. |
callbackfunction | Required. Specifies the callback function to be used. |