I found another way to do this without using global variables:
<?php $arr = array("a" => 12, "b" => function($num) { $c = $num * 2; return $c; }); echo $arr["b"]($arr["a"]); ?>
Note the weird syntax for ending an array index call using the method parentheses. By passing $arr["a"] as a parameter, you can access this value (I think you could follow the link too).
If you were not to pass anything into an anonymous function, you would call it the following:
$arr["b"]();
If you do not include the brackets of the method, this will not work.
source share