In order for it to work, you need to pass $factorial as a reference
$factorial = function( $n ) use ( &$factorial ) {
if( $n == 1 ) return 1;
return $factorial( $n - 1 ) * $n;
};
print $factorial( 5 );
More Related Contents:
- How to call a closure that is a class variable?
- Use keyword in functions – PHP [duplicate]
- In PHP, what is a closure and why does it use the “use” identifier?
- How to search by key=>value in a multidimensional array in PHP
- What in layman’s terms is a Recursive Function using PHP
- Recursive function to generate multidimensional array from database result
- Calling closure assigned to object property directly
- List all the files and folders in a Directory with PHP recursive function
- Cartesian Product of N arrays
- How to use return inside a recursive function in PHP
- Search for a key in an array, recursively
- Multidimensional array iteration
- Exception: Serialization of ‘Closure’ is not allowed
- PHP Create a Multidimensional Array from an array with relational data [duplicate]
- Php recursion to get all possibilities of strings
- How to run array_filter recursively in a PHP array?
- Deep recursive array of directory structure in PHP
- PHP recursive directory path
- PHP 5.4 – ‘closure $this support’
- Echo menu tree with recursive function
- Converting an array from one to multi-dimensional based on parent ID values
- How to obtain a nested HTML list from object’s array recordset?
- PHP – How to build tree structure list?
- PHP – Listing all directories and sub-directories recursively in drop down menu [duplicate]
- recursive function to get all the child categories
- Convert array of paths into UL list
- How can I sum all values of a specific array key recursively?
- Get sum from nodes tree
- PHP convert nested array to single array while concatenating keys?
- Callback function using variables calculated outside of it