1.

What is array filter in PHP?

Answer»

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)
Also Read: How to Use TRAITS in PHPExample

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"));



Discussion

No Comment Found