Why did the user decide to remove recursion from the function?

The user decided to remove recursion from the function because it was causing the program to run into a stack overflow error due to excessive function calls. To solve this issue, the user can refactor the function to use iteration instead of recursion. By using a loop structure, the function can achieve the same result without the risk of hitting the stack limit.

function calculateFactorial($n) {
    $result = 1;
    
    for ($i = 1; $i <= $n; $i++) {
        $result *= $i;
    }
    
    return $result;
}

// Example usage
echo calculateFactorial(5); // Output: 120