Published on January 26, 2024By DeveloperBreeze
// Function to calculate factorial using recursion
function factorial($n) {
if ($n === 0) {
return 1;
}
return $n * factorial($n - 1);
}
// Usage: Calculate factorial of 5
$result = factorial(5);
Comments
Please log in to leave a comment.