It seems that a static variable declared in a function is re-initiated whenever the function is called, how can I use the function in a way that re-calling the function will re-use the static parameter?
I defined the function 'testStatic' in static.php
here is static.php:
<?php
function testStatic()
{
static $staticV = 0;
echo $staticV;
$staticV;
}
?>
I am calling 'testStatic' from index.php
here is index.php:
<?php include "./static.php";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3c.org/TR/html4/strict.dtd">
<?php
testStatic();
?>
<html>
.
.
.
<html>
When index.php is executed for the first time testStatic will echo with '0' however in the next times index.php is executed testStatic continues to echo with '0'. It seems that the static variable 'staticV' of 'testStatic' is re-initiated whenever index.php is execute.
please advise. that index.php