The value of a local variable of a function has to be retained over multiple calls to the function. How should that variable be declared in PHP?
views:
40answers:
1
+11
A:
using static
. example:
function staticDemo() {
static $x =1;
echo $x;
$x++;
}
the variable $x
gets that static value the first time the function is called, afterwards it retains it's state.
example:
staticDemo(); // prints 1
staticDemo(); // prints 2
staticDemo(); // prints 3
GSto
2010-06-29 15:11:10