PHP闭包和回调

Mar*_*tin 2 php closures function callback

我正在学习闭包,但我坚持这个:

function addPrefix($string) {
    return function($prefix) use ($string) {
        echo $prefix.$string;
    };
}
$randomstring = "a test";
$c = addPrefix($randomstring);
echo $c("This is ");
Run Code Online (Sandbox Code Playgroud)

为什么$前缀连接在一起?它甚至不被称为争论,我只是不明白.

Vin*_*des 5

在你的例子中注意有2个功能.addPrefix,以及addPrefix返回的匿名函数.

那么,$c这个匿名函数(由addPrefix返回)是否具有$ prefix参数.