为什么回调函数在array_filter()里面没有起作用?

WBOY
Release: 2016-06-23 14:26:04
Original
1194 people have browsed it

array_filter() 回调函数

	<?php		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"));	 ?>
Copy after login


回复讨论(解决方案)

去看下array_filter 的用法就会明白

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"));
Copy after login

明白了,谢谢两位

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template