A static variable is defined within a function only the first time and its value can be modified during function calls as follows: <?php function testFunction() { static $testVariable = 1; echo $testVariable; $testVariable++; } testFunction(); //1test Function(); //2test Function(); //3?>
PHP
Topic: Variables
what is the static variable in function useful for?
Browse random answers:
What is Variables?
What is PHP Variables?
How do you declaring a variable?
Explain the difference between $message and $$message.
How can we check the value of a given variable is a number?
How do I check if a given variable is empty?
what is the static variable in function useful for?
How can we define a variable accessible in functions of a PHP script?
How can you pass a variable by reference?
If the variable $var1 is set to 10 and the $var2 is set to the character var1, what’s the value of $$var2?
What does $GLOBALS means?
What does $_ENV means?