Look at the code below.
function test () {$param 2 = ' every ';//Returns an anonymous function ($param 1) use ($param 2) {///using clause to let anonymous function uses its scope variable $param2. = ' O Ne ';p rint $param 1. ' ' . $param 2;};} $anonymous _func = Test (); $anonymous _func (' hello ');
The output is Hello World
$param 1 and $param2 are closure variables
The following way outputs Hello everyone
function test () {$param 2 = ' everyone '; $func = function ($param 1) use ($param 2) {///using clause let anonymous function uses the variable of its parent scope print $param 1. ' ' . $param 2;}; $param 2 = ' everybody '; return $func;} $anonymous _func = Test (); $anonymous _func (' hello ');
The following way outputs Hello everybody
More than one reference in $param 2
function test () {$param 2 = ' everyone '; $func = function ($param 1) using (& $param 2) {//USE clause let anonymous function uses the variable of its parent scope print $param 1 . ' ' . $param 2;}; $param 2 = ' everybody '; return $func;} $anonymous _func = Test (); $anonymous _func (' hello ');