Why does the callback function not work in array_filter? & Lt ;? Phpfunction & nbsp; myFunction ($ v) & nbsp; {if & nbsp; ($ v = "Dog") {return & nbsp; "Fido ";} return & nbsp; $ v; why does the callback function not work in array_filter?
Function myFunction ($ v)
{
If ($ v = "Dog ")
{
Return "Fido ";
}
Return $ v;
}
$ A = array ("Horse", "Dog", "Cat ");
// Array ([0] => Horse [1] => Fido [2] => Cat)
Print_r (array_map ("myFunction", $ ));
// Array ([0] => Horse [1] => Dog [2] => Cat)
// Why does the callback function not work in array_filter?
Print_r (array_filter ($ a, "myFunction "));
?>
The callback function of array_filter () is shared:
------ Solution --------------------
You can see the usage of array_filter.
------ Solution --------------------
Function myFunction ($ v)
{
If ($ v = "Dog ")
{
Return true;
}
Return false;
}
$ A = array ("Horse", "Dog", "Cat ");
// Array ([0] => Horse [1] => Fido [2] => Cat)
Print_r (array_map ("myFunction", $ ));
// Array ([0] => Horse [1] => Dog [2] => Cat)
// Why does the callback function not work in array_filter?
Print_r (array_filter ($ a, "myFunction "));