Thursday, April 20, 2017

Static Variable

<?php
$counter = 5;
function init() {
 static $counter = 1;
 $counter++;
 echo "<br/> within function init(): \$counter: " . $counter . "<br/>";
}
echo "In script, \$counter: " . $counter;
init();
echo "In script, after init(), \$counter: " . $counter;
init();
?>
Output:
In script, $counter: 5
within function init(): $counter: 2
In script, after init(), $counter: 5
within function init(): $counter: 3

No comments:

Post a Comment

here docs

$x = <<<THE_END PHP stands for "PHP: Hypertext Preprocessor". The acronym "PHP" is therefore, usually referre...