Hors">
时间:2021-07-01 10:21:17 帮助过:3人阅读
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",$a));
//Array ( [0] => Horse [1] => Dog [2] => Cat )
//为什么回调函数在array_filter()里面没有起作用?
print_r(array_filter($a,"myFunction"));
?>
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",$a));
//Array ( [0] => Horse [1] => Dog [2] => Cat )
//为什么回调函数在array_filter()里面没有起作用?
print_r(array_filter($a,"myFunction"));