Reputation: 23188
$count = 2;
$amt = 4;
$str = function($count, $amt) {
return "There is ". $count . " and " . $amt;
};
echo $str . "!";
How do I store the return value from the anonymous function into a variable? I know that the entire function itself is being stored into $str which is why this doesn't work, but is there a way to?
Upvotes: 0
Views: 48
Reputation: 2289
You should simply call $str
as a function:
echo $str() . "!"
Documentation for anonymous functions as php.net: http://www.php.net/manual/en/functions.anonymous.php
Upvotes: 2