while reading abt array_filter() from php manual,came to face example to demostrate
the same function using callback function as given below
<?php
function odd($var)
{
// returns whether the input integer is odd
return($var & 1);
}
function even($var)
{
// returns whether the input integer is even
return(!($var & 1));
}
$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);
$array2 = array(6, 7, 8, 9, 10, 11, 12);
echo "Odd :\n";
print_r(array_filter($array1, "odd"));
echo "Even:\n";
print_r(array_filter($array2, "even"));
?>
can you please help me to know how actually calback function calling,actual parameter pass,working?
any link to demostrate about callback wld be great help.
In the two given examples,
array_filterwill go over the values in the passed array and send each value in it to the callback function (oddoreven). The callback function will then inspect the value to see whether it is odd or even and returnTRUEorFALSE. If it returnsFALSE, the value is filtered from the array.The easiest way to find out what your function is passing to your callback is to supply a callback that prints the passed arguments, e.g.
Callbacks are described in detail at