PHP Interview Questions and Answers

 

what is the static variable in function useful for?

A static variable is defined within a function only the first time and its value can be modified during function calls as follows:
?
1
2
3
4
5
6
7
8
9
function testFunction() { static $testVariable = 1;
echo $testVariable;
$testVariable++;
}
testFunction(); //1
testFunction(); //2
testFunction(); //3
?>

Posted by:Richards