recursion - How to build an anonymous recursive function in PHP?

one text

Solution:

Yes you can. You need to use the $greet variable by reference, like this:

$greet = function($name) use (&$greet)
{
    printf("Hello %s\r\n", $name);
    if($name != 'PHP')
    {
        $greet('PHP');
    }
};

$greet('World');

Working example:
https://3v4l.org/vUhIW

This article describes this a bit more:
https://fragdev.com/blog/php-recursion-with-anonymous-functions

Source