function MyFunc ()
- {
- Static $int;
$int = 0;
echo $int +1. " ";
- }
- Echo MyFunc ();
- Echo MyFunc ();
- Echo MyFunc ();
?>
Copy CodeThree values in the book are three-in-one. However, the true result is not operational, syntax error, and post-check error is due to $int+1. " "The wording of this sentence should be written ($int + 1)." ", the program does not error after the change, but the value is 1,1,1; in fact, this is not difficult to explain, $int although the constant increase of 1, but the results have not been assigned to $int, talk about what $int will increase. The code is correct if you modify it to the following:
- function MyFunc ()
- {
- static $int = 0; PHP static variable definition
- $int = $int +1;
- echo $int. "
";
- }
- Echo MyFunc ();
- Echo MyFunc ();
- Echo MyFunc ();
- ?>
Copy CodeNote that the static keyword must be combined with the assignment (the use of the PHP static variable modifier), if written in a book STAITC $int; $int = 0;Error, the result of the run is also 1,1,1 |