Skip to content

Instantly share code, notes, and snippets.

@LGitHub-sprout
Created November 3, 2020 14:38
Show Gist options
  • Save LGitHub-sprout/833cf0d1e745f85441b6cf2ba907744e to your computer and use it in GitHub Desktop.
Save LGitHub-sprout/833cf0d1e745f85441b6cf2ba907744e to your computer and use it in GitHub Desktop.
/**
* Static variables keep their value after function calls.
* useful for making counters to track number of function calls.
* bc $count has already been declared, initialization is skipped.
* it retains previous value, then is incremented and is displayed w new value.
*
* can only be assigned w predetermined value.
* cannot assign the result of an expression.
*/
function test() {
static $count = 0;
echo '<p>$count is: ' . $count . '</p>';
++$count;
}
test();
test();
test();
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment