php如何读取temp函数中的局部变量?
我注意到PHP现在可以使用临时函数定义(如js和其他脚本语言),但是如何在临时函数中获取局部变量呢 例:php如何读取temp函数中的局部变量?,php,function,scope,Php,Function,Scope,我注意到PHP现在可以使用临时函数定义(如js和其他脚本语言),但是如何在临时函数中获取局部变量呢 例: use将完成此任务 function my_func($text, $prefix){ $regex = '/xxxx/'; return preg_replace_callback($regex, function($matches) use(&$prefix){
use
将完成此任务
function my_func($text, $prefix){
$regex = '/xxxx/';
return preg_replace_callback($regex, function($matches) use(&$prefix){
//^^^^^^^^^^^^^
}, $text);
}
我发现
是的,可能重复,但这个问题的标题太难找到。。
function my_func($text, $prefix){
$regex = '/xxxx/';
return preg_replace_callback($regex, function($matches) use(&$prefix){
//^^^^^^^^^^^^^
}, $text);
}
function my_func($text, $prefix){
$regex = '/xxxx/';
return preg_replace_callback($regex, function($matches) use ($prefix){
// how to read $prefix here?
}, $text);
}