Home >Backend Development >PHP Tutorial >How to Create Recursive Anonymous Functions in PHP?
Creating Recursive Anonymous PHP Functions
It can be advantageous to create anonymous functions that are recursive in PHP. The code below demonstrates how to accomplish this, passing a function as a reference.
$factorial = function( $n ) use ( &$factorial ) { if( $n == 1 ) return 1; return $factorial( $n - 1 ) * $n; }; print $factorial( 5 );
The above is the detailed content of How to Create Recursive Anonymous Functions in PHP?. For more information, please follow other related articles on the PHP Chinese website!