84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
我在当前页面的控制器里面写的 $name也都有值 我就是想刷新一次当前页面后就执行一次这个count函数 这样写为什么不行呢?这样写每次得到的都是同一个值
$name=I('t'); function count(){ static $a=0; ++$a; echo $a; } if(!empty($name)){ count(); }
How to increase $a by one every time the page is refreshed? -PHP Chinese website Q&A-How to increase $a by one every time the page is refreshed? -PHP Chinese website Q&A
Let’s take a look and learn.
$name=I('t'); function count(){ // 首先判断session中是否已设置名为a的值 if(session('?a')) { // 此行用原生php也可写成 if(isset( $_SESSION['a'] )) $a = session('a'); // 已经设置,则从session中取出值 }else{ $a=session('a',0); // 没有设置,则设置初始值0 } $a++; echo $a; session('a', $a); // 把a的值保存到session中以便下次使用。 } if(!empty($name)){ count(); }
仅供参考
How to increase $a by one every time the page is refreshed? -PHP Chinese website Q&A-How to increase $a by one every time the page is refreshed? -PHP Chinese website Q&A
Let’s take a look and learn.
仅供参考