解析PHP可变函数的经典用法
时间:2024-06-05 09:38:32
<?php
function map($fun, $list,$params=array()){
$acc=NULL;
$last=array_push($params, NULL,$acc)-1;
foreach($list as $params[$last-1]){ //第一次见这种写法感觉很神奇
$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 = $result\n";
$result=0;
$result=map('addTo',array(1,2,3));
echo "result= $result\n";
?>
这样以后累加 类似的计算就方便多了。。。
标签:PHP,可变函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决Python3错误:SyntaxError: unexpected EOF while parsin
2022-02-08 10:18:32
JavaScript解决Joseph问题
2008-06-21 17:11:00
Mysql四种分区方式以及组合分区落地实现详解
2024-01-23 05:05:25
查找MySQL线程中死锁的ID的方法
2024-01-12 18:28:34
JavaScript 模拟类机制及私有变量的方法及思路
2024-05-03 15:04:55
javascript实现tab响应式切换特效
2024-02-25 00:13:12
Vue 全部生命周期组件梳理整理
2023-07-02 16:32:44
termux中matplotlib无法显示中文问题的解决方法
2022-12-16 00:07:16
![](https://img.aspxhome.com/file/2023/6/128516_0s.png)
Python OpenCV招商银行信用卡卡号识别的方法
2022-01-16 06:31:30
![](https://img.aspxhome.com/file/2023/5/83785_0s.jpg)
windows下python安装小白入门教程
2022-01-05 08:45:44
![](https://img.aspxhome.com/file/2023/9/90439_0s.jpg)
Django将默认的SQLite更换为MySQL的实现
2024-01-14 15:45:15
Python 处理带有 \\u 的字符串操作
2022-01-24 03:43:13
![](https://img.aspxhome.com/file/2023/7/79397_0s.jpg)
基于python的mysql复制工具详解
2023-06-24 01:08:28
![](https://img.aspxhome.com/file/2023/1/68131_0s.jpg)
pandas 获取季度,月度,年度首尾日期的方法
2022-08-16 06:53:06
python统计文本文件内单词数量的方法
2021-09-20 17:51:55
Typora 1.4.8激活 2022最新Typora破解激活使用教程
2022-02-13 18:14:59
![](https://img.aspxhome.com/file/2023/4/132364_0s.jpg)
Python Pytorch深度学习之核心小结
2021-05-26 20:03:50
![](https://img.aspxhome.com/file/2023/1/69631_0s.png)
golang实现单点登录系统(go-sso)
2024-02-20 11:52:45
Python实战小程序利用matplotlib模块画图代码分享
2021-08-27 18:31:47
![](https://img.aspxhome.com/file/2023/6/117866_0s.png)
XML卷之实战锦囊(1):动态排序
2008-09-05 17:20:00