The reason for this is that you are calling a function from within a function.
Here is a quick diagram of whats happening and the value of $count the whole way through:
(this aint code - i just want spacing)
echo.... calls staticTest
$count = 0
++ --> $count = 1
1 displayed
staticTest calls static Test (with value of 1 passed on)
$count = 1
++ --> $count = 2
2 displayed
staticTest calls static Test (with value of 2 passed on)
$count = 2
++ --> $count = 3
3 displayed
staticTest calls static Test (with value of 3 passed on)
....... $count = 9
++ --> $count = 10
this function then closes returning 10
returns 9
.........................
a value of 1 is returned to the original function called but nothing is done with this value - the function ends and so doesnt return anything.
You need to make a loop rather than a recursive function for this:
for ($count = 0; $count < 10; $count ++)
echo "in function: $count<br>\n";
return $count;
Recursive functions are used when the same thing is done over and over. For example, a tree listing of directories:
usage: functionname(dir)
- open dir and read all dirs inside it
- for each dir found, put back into function so all dirs inside that dir is displayed....
also note that when a funtion is called it creates a new function that is run then PHP continues from where the function was called from so in reality you called a function which called a function which called a function..... and the values where not used when passed back.
Hope that helps - its hard to explain using only words. If you have any questions, just ask.