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.

Continue Reading:

Calculate Factorial

Published on January 26, 2024

pythonjava

Generate Fibonacci Sequence

Published on January 26, 2024

python

Fibonacci Sequence in JavaScript

Published on January 26, 2024

javascript