php闭包函数怎么使用外部变量

如题所述

使用use关键词引入变量即可,请看代码:

<?php
function callFunc($callback) {
    return call_user_func($callback);
}

$author = 'Zjmainstay';
echo callFunc(function() use($author) {    #这里
    return "The author is {$author}";
});
温馨提示:答案为网友推荐,仅供参考
相似回答