0

how to use recursion in php

5th Nov 2022, 1:34 PM
Krupal Mehta
Krupal Mehta - avatar
1 Answer
+ 4
function factorial($n) { if ($n < 0) return -1; if ($n == 0) return 1; return ($n * factorial ($n -1)); } You can do recursion in PHP like this it's a simple function to find factorial of a number.
5th Nov 2022, 1:42 PM
Random
Random - avatar