$count = 2;
$amt = 4;
$str = function($count, $amt) {
return "There is ". $count . " and " . $amt;
};
echo $str . "!";
如何将匿名函数的返回值存储到变量中? 我知道整个函数本身都存储在$ str中,这就是为什么这不起作用,但有办法吗?
$count = 2;
$amt = 4;
$str = function($count, $amt) {
return "There is ". $count . " and " . $amt;
};
echo $str . "!";
如何将匿名函数的返回值存储到变量中? 我知道整个函数本身都存储在$ str中,这就是为什么这不起作用,但有办法吗?
你应该简单地将$str
作为函数调用:
echo $str() . "!"
匿名功能php.net文档: http://www.php.net/manual/en/functions.anonymous.php