//PHP closures Implement the self-invocation of functions, that is, to implement recursionfunctionClosure$n,$counter,$max){ //anonymous function, here the function of the parameter plus & symbol is, the address of the call parameter itself $FN=function(&$n,&$counter,&$max=1) Use(&$FN){//The use parameter passes the function closure function itself $n++; if($n<$max){//Recursive point, which is the condition of recursion $counter.=$n.‘ <br/> '; //Call yourself recursively $FN($n,$counter,$max); } return $counter; };//Remember that there must be a ";" semicolon, no semicolon PHP will error, closure function /** The return value of the function closure is the anonymous function that calls the closure * and the closure function, which refers to the parameters passed in by the closure function .*/ return $FN($n,$counter,$max); }Echo(Closure (0, ', 10));
PHP calls itself in an anonymous function.