Home > Backend Development > PHP Tutorial > Analyze the classic usage of PHP variable functions_PHP tutorial

Analyze the classic usage of PHP variable functions_PHP tutorial

WBOY
Release: 2016-07-21 15:05:00
Original
964 people have browsed it

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. . .

www.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...
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