I have a displayNumber code which prints the input number if its greater than 1 and then calls the displayNumber function again with the number - 1.
function displayNumber($number) {
if ($number >= 1) {
echo $number;
displayNumber($number-1);
}
return;
}
displayNumber(10);
The output would be: 10987654321
But after swapping the echo and displayNumber lines:
function displayNumber($number) {
if ($number >= 1) {
displayNumber($number-1);
echo $number;
}
return;
}
displayNumber(10);
The output is now: 12345678910
I can't understand this behavior of PHP.