PHP函数式编程
echo '<pre>';
function memoize($fun){
$list =[];
return function($arg)use($fun,&$list){
$key = md5(json_encode($arg));
if(!empty($list[$key])){
print_r('我是缓存'.PHP_EOL);
return $list[$key];
}
return $list[$key] =$fun($arg);
};
}
$ff=memoize(function ($r){
return $r * $r;
});
print_r($ff(9999)).PHP_EOL;
print_r($ff(9999)).PHP_EOL;
print_r($ff(9999)).PHP_EOL;
//99980001我是缓存
//99980001我是缓存
//99980001