The array_filter() method filters the values of an array the usage of a callback function. This method passes each value of the input array to the callback function. If this callback function returns true then the current value from the input is returned into the result array.

Syntax:

array_filter(array, callbackfunction, flag)

  • array(Required)
  • callbackfunction(Optional)
  • flag(Optional)
BY Best Interview Question ON 07 Apr 2020

Example

function test_odd_number(int $var)
{
   return($var & 1);
}
$array=array(1,3,2,3,4,5,6);
print_r(array_filter($array,"test_odd_number"));