php7 static variables difference between ordinary variables

php7 static variables and differences between ordinary variables
and variables declared function parameters (destroyed when the function is completed) In contrast, when the function exits, static variables do not lose their value, if the function is called again, which will remain static variables value. 96net.com.cn

<?php
function keep_track() {
static $count = 0;
$count++;
print $count;
}

keep_track();
keep_track();
keep_track();
?>

This will produce the following results -

1
2
3

Ordinary variables

<?php
function keep_track() {
static $count = 0;
$count++;
print $count;
}

keep_track();
keep_track();
keep_track();
?>

This will produce the following results -

2
2
2

Guess you like

Origin blog.51cto.com/13959155/2462719