Programming-Idioms

History of Idiom 31 > diff from v47 to v48

Edit summary for version 48 :
New PHP implementation by user [nek]

Version 47

2019-09-26, 13:57:01

Version 48

2019-09-26, 14:01:55

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);
}