Accessing External Variables of Anonymous Functions in PHP
You can make external variables
available inside an anonymous function.
To do this, you need to declare these variables
using the use construct
as follows:
<?php
$num1 = 1;
$num2 = 2;
$func = function() use ($num1, $num2)
{
echo $num1 + $num2;
};
$func();
?>
Fix the problem in this code:
<?php
$num = 5;
$func = function()
{
return $num ** 2;
};
echo $func();
?>