我注意到PHP现在可以使用临时函数定义(如js和其他脚本语言),但是如何在temp函数中获取局部变量?
例如:
function my_func($text, $prefix){
$regex = '/xxxx/';
return preg_replace_callback($regex, function($matches){
// how to read $prefix here?
}, $text);
}
该use
会做的工作..
function my_func($text, $prefix){
$regex = '/xxxx/';
return preg_replace_callback($regex, function($matches) use(&$prefix){
//^^^^^^^^^^^^^
}, $text);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句