How does the order of execution change in a recursive function when the echo statement is moved within the function?

Moving the echo statement within a recursive function can change the order of execution because the echo statement will be executed each time the function calls itself. This can lead to the echo statements being printed in a different order than expected. To solve this issue, you can move the echo statement outside of the recursive function and pass the echoed string as a parameter to the function.

function recursiveFunction($n, $output = '') {
    if ($n > 0) {
        $output .= "Number: $n\n";
        return recursiveFunction($n - 1, $output);
    }
    return $output;
}

echo recursiveFunction(5);