首页 > 代码库 > PHP Array_Map
PHP Array_Map
<?phpfunction myfunction($v) {if ($v==="Dog") { return "Fido"; }return $v;}$a=array("Horse","Dog","Cat");print_r(array_map("myfunction",$a));?>
输出:
Array ( [0] => Horse [1] => Fido [2] => Cat )
<?phpfunction myfunction($v1,$v2) {if ($v1===$v2) { return "same"; }return "different";}$a1=array("Horse","Dog","Cat");$a2=array("Cow","Dog","Rat");print_r(array_map("myfunction",$a1,$a2));?>
输出:
Array ( [0] => different [1] => same [2] => different )
请看当自定义函数名设置为 null 时的情况:
<?php$a1=array("Dog","Cat");$a2=array("Puppy","Kitten");print_r(array_map(null,$a1,$a2));?>
输出:
Array ([0] => Array ( [0] => Dog [1] => Puppy )[1] => Array ( [0] => Cat [1] => Kitten ))
PHP Array_Map
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。