直接上代码吧:# 向返回的闭包函数实例中,传递外部变量参数# 直接调用将不会输出$txt的内容 function demo(){ $txt
直接上代码吧:
# 向返回的闭包函数实例中,传递外部变量参数 # 直接调用将不会输出$txt的内容 function demo(){ $txt = '我爱PHP'; # 1、function()内的变量,为父类实例外部可传递的变量 # 2、use()内的变量,为实例父类实例内部可传递的变量 $func = function($str='') use($txt){ echo $txt; echo '<br/>'; echo $str; }; # 这里不再直接调用,而且是把实例返回 return $func; } # 测试一下 $res = demo(); // 函数返回实例 $obj = $res('我爱Delphi'); // 再通过res()调用,没有这一步,将不会输出$txt
赞
(0)
打赏
微信扫一扫
支付宝扫一扫


thinkphp5.0 安装think-queue composer 报错 版本不符
上一篇
2019年12月31日 07:06
react or js原生 input输入框从光标位置插入内容
下一篇
2020年01月06日 12:07
这里是广告位
相关推荐
-
readfile(): Unable to find the wrapper ".http" - did you forget to enable it when you configured PHP?
readfile(): Unable to find the wrapper ".http" - did you forget to enable it when you configured PHP?
-
PHP使用strtotime("-1 month", time())得到上个月是错的
今天是3月30号,使用strtotime得到的不是2月份,而是3月份。解决方法是可以把时间戳先转换成年月,$t = date(Y-m);然后再使用strtoti