Static variables exist only in the scope of the function, the static variable only exists in the stack, the next time the function is called, the value of the variable will be preserved
Static variables exist only within the scope of a function, and static variables live only on the stack. Normal variables are released after the function ends, such as local variables, but static variables do not. The next time the function is called, the value of the variable is preserved. The basic usage of a static variable is 1. Define a static variable [access modifier] static $ variable name in the class; 2. How to access static variables if there are two ways to access a static variable name in a class, class name:: $ static variable name if accessed outside the class: There is a method class name:: $ static Variable name example code is as follows: Class child{public $name; This defines and initializes a static variable $nums public static $nums = 0; function __construct ($name) {$this->name= $name; Public Function Join_game () {//self:: $nums using static variable self:: $nums +=1; echo $this->name. " Add snowmen Game "; }//Create three children $child 1=new child ("Likui"); $child 1->join_game (); $child 2=new Child ("Zhang Fei"); $child 2->join_game (); $child 3=new Child ("Tang's Monk"); $child 3->join_game (); See how many people play the game echo "<br/> have this". Child:: $nums;