php 回调函数1...
时间:2010-08-06 来源:zipu888
<?php
/*
* Created on 2010-7-28
* Writen by Hope
* Xiao you are the best! Come on
* PHPeclipse
*/
//单个数组使用的例子
$websites = array("g"=>"google","b"=>"baidu","y"=>"yahoo");
function value_alter ($value) {
return ucfirst($value).".com";
}
$urls = array_map("value_alter",$websites);
//返回一个数组,数组包含了$websites中所有元素经过回调函数处理之后的单元
//回调函数接受的参数数目应该和传递给array_map函数的数组数目一致
print_r($websites);
echo "<hr>";
print_r($urls);
echo "<hr>";
//多个数组使用的例子
$a = array(1,2,3);
$b = array(7,8,9);
function value_multi ($a,$b) {
return $a*$b;
}
$results = array_map("value_multi",$a,$b);
print_r($a);
echo "<hr>";
print_r($b);
echo "<hr>";
print_r($results);
?>