Skip to content

Instantly share code, notes, and snippets.

@rmamont
Last active March 29, 2017 06:16
Show Gist options
  • Select an option

  • Save rmamont/e281d534ad3a63f3ef0f3588fca73f09 to your computer and use it in GitHub Desktop.

Select an option

Save rmamont/e281d534ad3a63f3ef0f3588fca73f09 to your computer and use it in GitHub Desktop.

Revisions

  1. rmamont revised this gist Mar 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion calc factorial in iterative method
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,4 @@ function fctrl($num) {
    return $iter($num, 1);
    }

    echo fctrl(5), PHP_EOL;
    echo fctrl(97), PHP_EOL;
  2. rmamont created this gist Mar 29, 2017.
    15 changes: 15 additions & 0 deletions calc factorial in iterative method
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?php

    function fctrl($num) {
    $iter = function($num, $acc) use (&$iter) {
    if ($num == 1) {
    return $acc;
    }

    return $iter($num - 1, $acc * $num);
    };

    return $iter($num, 1);
    }

    echo fctrl(5), PHP_EOL;