- #1
- 2,020
- 827
The code
is supposed to generate
0
1
2
My question is this: If we declare $x = 0 in the function then why doesn't it reset to 0 every time we run the function?
-Dan
<?php
function myTest() {
static $x = 0;
echo $x;
$x++;
}
myTest();
echo "<br>";
myTest();
echo "<br>";
myTest();
?>
is supposed to generate
0
1
2
My question is this: If we declare $x = 0 in the function then why doesn't it reset to 0 every time we run the function?
-Dan