Skip to content

Instantly share code, notes, and snippets.

@nezarfadle
Created April 13, 2020 20:50
Show Gist options
  • Save nezarfadle/f2630e9b5c677af8f7b23c0ea82a040a to your computer and use it in GitHub Desktop.
Save nezarfadle/f2630e9b5c677af8f7b23c0ea82a040a to your computer and use it in GitHub Desktop.
<?php

function countup( $steps )
{

    // Internal State
    $counter = 1;   

    $run = function() use ( $steps, &$counter, &$run )
    {

        if( $counter > $steps ) return;
        echo $counter++;
        
        // Calling the Inner Function Recursively
        $run();     
        
    };

    $run();

}

countup( 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment