Copy code The code is as follows:
function map($fun, $list,$params=array( )){
$acc=NULL;
$last=array_push($params, NULL,$acc)-1;
foreach($list as $params[$last-1]){ // It feels amazing to see this writing method for the first time
$params[$last]=call_user_func_array($fun, $params);
}
$acc=array_pop($params);
return $ acc;
}
function add($element,$acc){
if ($acc == NULL);
return $acc=$element+$acc;
}
$result=0;
$result=addTo($result,1);
$result=addTo($result,2);
$result=addTo($result,3);
echo "result = $resultn";
$result=0;
$result=map('addTo',array(1,2,3));
echo "result= $resultn";
?>
This will make it much more convenient to accumulate similar calculations in the future. . .
http://www.bkjia.com/PHPjc/327722.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327722.htmlTechArticleCopy the code as follows: ?php function map($fun, $list,$params=array()){ $acc=NULL; $last=array_push($params, NULL,$acc)-1; foreach($list as $params[$last-1]){ //First time seeing this...