Junior PHP Developer Question:
Explain what is the static variable in function useful for?
Answer:
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(); //1
testFunction(); //2
testFunction(); //3
?-->
<!--?php
function testFunction()
{
static $testVariable = 1;
echo $testVariable;
$testVariable++;
}
testFunction(); //1
testFunction(); //2
testFunction(); //3
?-->
Previous Question | Next Question |
Tell me how the result set of Mysql be handled in PHP? | What is faster in PHP? |