Skip to content

Instantly share code, notes, and snippets.

@aerith
Created August 15, 2012 12:17
Show Gist options
  • Select an option

  • Save aerith/3359652 to your computer and use it in GitHub Desktop.

Select an option

Save aerith/3359652 to your computer and use it in GitHub Desktop.

Revisions

  1. aerith created this gist Aug 15, 2012.
    18 changes: 18 additions & 0 deletions bar.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?php

    function bar ($n) {
    return implode('', array_pad(array(), $n, '#')) . implode('', array_pad(array(), 100 - $n, '-'));
    }

    array_map(function ($i) {
    printf('%3d%% [|%s|]', $i, bar($i));
    usleep(2000000);
    print "\r";
    }, range(1, 100));

    print "\n";

    // From:
    // => 1% [|#---------------------------------------------------------------------------------------------------|]
    // To:
    // => 100% [|####################################################################################################|]