码迷,mamicode.com
首页 > Web开发 > 详细

PHP Array_Map

时间:2014-09-03 14:55:56      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   cti   sp   log   

<?php
function 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 )

<?php
function 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

标签:style   blog   color   io   ar   div   cti   sp   log   

原文地址:http://www.cnblogs.com/dangkei/p/3953622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!