How can parameter order affect the output of recursive functions in PHP?

The parameter order in recursive functions in PHP can affect the output if the parameters are not passed in the correct order. This can lead to unexpected results or errors in the function's behavior. To avoid this issue, make sure to pass the parameters in the correct order according to the function's definition.

// Incorrect parameter order example
function factorial($n, $result = 1) {
    if ($n == 0) {
        return $result;
    }
    return factorial($result * $n, $n - 1);
}

echo factorial(5); // Incorrect output due to incorrect parameter order

// Correct parameter order example
function factorial($n, $result = 1) {
    if ($n == 0) {
        return $result;
    }
    return factorial($n - 1, $result * $n);
}

echo factorial(5); // Correct output with parameters in the correct order