This article mainly introduces the PHP closure. if you need it, you can refer to the example in this article to analyze the concept machine usage of the closure in PHP program design and share it with you for your reference. The specific analysis is as follows:
In general, closures are PHP anonymous functions, but unlike functions, closures can use the value of the variable in the scope of the function declaration when using the function declaration.
The specific form is as follows:
$ A = function ($ arg1, $ arg2) use ($ variable) {// declare the function closure to the variable $ a. The parameter is $ arg1, $ arg2, the closure must use the $ variable}
The usage example is as follows:
<? Php $ result = 0; $ one = function () {var_dump ($ result) ;}; $ two = function () use ($ result) {var_dump ($ result) ;}; // The variable $ two itself records the declaration of the function and the value of the variable used by use $ 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)?>
I hope this article will help you learn PHP programming.