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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With