PHP calls itself in an anonymous function.

Source: Internet
Author: User

//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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.