<?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