Blogger Information
Blog 250
fans 3
comment 0
visits 321059
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
关于静态变量的定义和使用方法
梁凯达的博客
Original
2461 people have browsed it

//根据储存方式不同,变量分为动态储存和静态储存

//1.普通变量(动态储存)

//$变量名=变量值

//函数名调用一次声明一次释放一次

//2.静态变量(静态储存)

// static $变量名 = 变量值

// 声明静态变量函数会在第一次运行函数的时候储存在内存中不释放

// 每次调用都会直接在内存中取出所有值

// 至于服务器重启之后,静态变量不会再纪录,又重新开始计算

function demo(){

$int = 1;

$int ++;

echo $int;

}

demo();

demo();

demo();

demo();

//以上输出的全都是2;

echo '<hr />';

function demo1(){

static $int=1;

$int++;

echo $int;

}

demo1();

demo1();

demo1();

demo1();

//从2/3/4/5


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!