我有这样的设置:
function test(){
function(){
return "testing!";
};
return;
}
echo test();
我试图让test()
函数返回“测试” (在这个例子中),但这不起作用。你有什么建议?
为什么要使用匿名函数? 我必须为此使用匿名函数,因为我使用的是 ReactPHP 的 HttpClient,这是一个基本示例,说明它是如何工作的:
$request = $client->request('GET', 'https://api.github.com/repos/reactphp/react/commits');
$request->on('response', function ($response) {
$buffer = '';
$response->on('data', function ($data) use (&$buffer) {
$buffer .= $data;
echo ".";
});
$response->on('end', function () use (&$buffer) {
$decoded = json_decode($buffer, true);
$latest = $decoded[0]['commit'];
$author = $latest['author']['name'];
$date = date('F j, Y', strtotime($latest['author']['date']));
echo "\n";
echo "Latest commit on react was done by {$author} on {$date}\n";
echo "{$latest['message']}\n";
});
});
$request->on('end', function ($error, $response) {
echo $error;
});
$request->end();
在上面的示例中,他们回显了页面的内容,但我想返回它,任何帮助将不胜感激。谢谢!