filter function with 2 call back functions
Posted: Thu Jan 04, 2018 5:32 pm
The functions work however I need to iterate an array and if "even" print the array value if "odd" print "odd"; The for loop doesn't print the $i value and it doesn't print "odd" either?
thanks
function odd($var)
{
return($var & 1);
}
function even($var)
{
return(!($var & 1));
}
for ($i=0; $i<= sizeof($arr); $i++){
if ($arr_filter($arr,'even')==1){
print_r($arr=>$i);
}elseif($arr_filter($arr,'odd')==1)
{
print_r('odd');
}
}
thanks
function odd($var)
{
return($var & 1);
}
function even($var)
{
return(!($var & 1));
}
for ($i=0; $i<= sizeof($arr); $i++){
if ($arr_filter($arr,'even')==1){
print_r($arr=>$i);
}elseif($arr_filter($arr,'odd')==1)
{
print_r('odd');
}
}