DeveloperBreeze

Recursive Factorial Calculation in PHP

php
// 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);

Related Posts

More content you might like

Code
javascript

Fibonacci Sequence in JavaScript

No preview available for this content.

Jan 26, 2024
Read More
Code
python

Generate Fibonacci Sequence

No preview available for this content.

Jan 26, 2024
Read More
Code
java

Calculate Factorial

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!