I have recently go through these examples of anonymous function, but i am not very clear about it, what is the difference between them, why in second function
use keyword
used and why first one return null and second one return 0:
<?php
$result = 0;
// first function
$one = function()
{ var_dump($result); };
// second function with use
$two = function() use ($result)
{ var_dump($result); };
$three = function() use (&$result)
{ var_dump($result); };
$result++;
$one(); // outputs NULL: $result is not in scope
$two(); // outputs int(0): $result was copied
$three(); // outputs int(1)
?>
Refrence link: http://php.net/manual/en/functions.anonymous.php