Logo

Programming-Idioms

History of Idiom 31 > diff from v54 to v55

Edit summary for version 55 by ancarda:
[PHP] Format code snippet to PSR-12

Version 54

2019-09-26, 21:54:41

Version 55

2019-09-26, 22:27:27

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
function f(int $i): int {
  if ($i == 0) {
    return 1;
  }

  return $i * f($i - 1);
}
Code
function f(int $i): int
{
    if ($i == 0) {
        return 1;
    }

    return $i * f($i - 1);
}