Hello!
The two code exampels below makes me confused.
function countxs($x) {
if ($x<3) {
$x++;
echo($x.", ");
countxs($x);
}
echo("<br>send: ".$x);
return $x;
}
$a = countxs(0);
echo(" ==> recived: ".$a."<br>");
This code will produce an output like this:
1, 2, 3,
send: 3
send: 3
send: 2
send: 1 ==> recived: 1
I would have excpected this:
send: 3 ==> recived: 3
If I use the foolowing code instead I get even more confused.
function countxs($x) {
if ($x<3) {
$x++;
echo($x.", ");
countxs($x);
}
else {
echo("<br>send: ".$x);
return $x;
}
}
$a = countxs(0);
echo(" ==> recived: ".$a."<br>");
It will produce an output like this:
1, 2, 3,
send: 3 ==> recived:
So, how could I get a (recursive) function that behaves as I excpect?
Thanks
/Markus