PHP code example of samlev / recursion-guard

1. Go to this page and download the library: Download samlev/recursion-guard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

samlev / recursion-guard example snippets


function bozo_repeat(string $repeat = ''): string
{
    return RecursionGuard\Recurser::call(
        // The callback that we want to call
        fn () => bozo_repeat() . ' : ' . bozo_repeat(),
        // What to return if this function is called recursively
        $repeat ?: 'bozo(' . random_int(0, 100)) . ')';
    );
}

bozo_repeat(); // 'bozo(4) : bozo(4)'
bozo_repeat('foo'); // 'foo : foo'
bozo_repeat(); // 'bozo(88) : bozo(88)'