What is the difference between using global directly in PHP’s anonymous function and using use to pass variables in external space?
What is the difference between using global directly in PHP’s anonymous function and using use to pass variables in external space?
The variables of the closure function use will not affect global variables.
<code><?php $global = $global2= 'hello'; $fun = function() use ($global){ $global.=' world!'; global $global2; $global2.=' world!'; }; $fun(); echo $global."\n"; //hello echo $global2; //hello world! </code>