function () use ($x, &$y){}
Since PHP5.3 began to have the concept of Closure/anonymous functions, the USE keyword here is to allow anonymous functions to capture to the parent function scope
$x and $y variables exist within the Where &&y is a reference capture, that is, each time the anonymous function is called, the value of Y
The changes are also reflected here, while $x is a static reference.
<?PHP$message= "Hello\n";$example=function () { Echo $message;};//notice:undefined variable:message$example();$example=function() Use($message) { Echo $message;};//"Hello"$example();//inherited variable ' s value was from when the function was defined, not when called$message= "world\n";//"Hello"$example();//Inherit by-reference$message= "Hello\n";$example=function() Use(&$message) { Echo $message;};//"Hello"$example();//The changed value in the parent scope was reflected inside the function call$message= "world\n";//"World"$example();//Closures can also accept regular arguments$example=function($arg) Use($message) { Echo $arg. ‘ ‘ .$message;};//"Hello World"$example("Hello");
PHP and Laravel knowledge points small accumulation