Created
November 3, 2020 14:38
-
-
Save LGitHub-sprout/833cf0d1e745f85441b6cf2ba907744e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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