Anonymous recursive function in PHP Last Updated : 28 Nov, 2018 Comments Improve Suggest changes 1 Likes Like Report Anonymous recursive function is a type of recursion in which function does not explicitly call another function by name. This can be done either comprehensively, by using a higher order function passing in a function as an argument and calling that function. It can be done implicitly, via reflection features which allow one to access certain functions depending on the current context, especially ,the current function. In theory of computer science, anonymous recursion is significant, as anonymous recursion is type of recursion in which one can implement recursion without requiring named functions . Use of Anonymous Recursion: Anonymous recursion is primarily of use in allowing recursion for anonymous functions. Particularly when they form closures or are used as callbacks, to avoid having to bind the name of the function. Alternatives: The of use named recursion and named functions. If an anonymous function is given,anonymous recursion can be done either by binding a name to the function, as in named functions. Program 1: php <?php // PHP program to illustrate the // Anonymous recursive function $func = function ($limit = NULL) use (&$func) { static $current = 10; // if condition to check value of $current. if ($current <= 0) { //break the recursion return FALSE; } // Print value of $current. echo "$current\n"; $current--; $func(); }; // Function call $func(); ?> Output: 10 9 8 7 6 5 4 3 2 1 Program 2: php <?php // PHP program to illustrate the // Anonymous recursive function $factorial = function( $num ) use ( &$factorial ) { // Base condition of recursion if( $num == 1 ) return 1; // return statement when $m is not equals to 1. return $factorial( $num - 1 ) * $num; }; // Function call print $factorial( 6 ); ?> Output: 720 Create Quiz Comment A Amaninder.Singh Follow 1 Improve A Amaninder.Singh Follow 1 Improve Article Tags : Web Technologies PHP PHP Programs Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like