这是我的功能
function sample($greet, $otherVar) {
$codigo = preg_replace_callback("/(**_(\w+))/",
function($matches) use ($greet) {
if($matches[1] == $otherVar) {
(...)
重点是..我的主函数接收 $ otherVar 作为参数..我想在匿名函数中使用这个值..
答案 0 :(得分:4)
您可以通过use
关键字执行此操作,就像您已为$greet
变量所做的那样。像这样:
function($matches) use ($greet, $otherVar) {