Preserving Variable Values with Static in PHP


Maintain the value of a variable between function calls with static.

Source Code

function testStatic() {
    static $count = 0;
    $count++;
    echo $count;
}
testStatic(); // 1
testStatic(); // 2
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments