如何从键模式开始删除,取消设置会话变量
钥匙就像
Guard_1660743344
Guard_4323340344
Guard_5343332233
.....
Guard_[dynamicvalue]
Run Code Online (Sandbox Code Playgroud)
如果会话密钥以"Guard_"开头,我想从托盘中删除所有会话变量
unset($_SESSION[$key]);
Run Code Online (Sandbox Code Playgroud)
对不起,我尽力找到解决方案,但失败了,因此问道
我想foreach在这种情况下循环将是最好的:( 工作eval.in)
<?php
foreach(array_keys($_SESSION) as $key) // loop over all keys of the session
if(substr($key,0,6)=='Guard_') // if the key starts with Guard_
unset($_SESSION[$key]); // unset it
?>
Run Code Online (Sandbox Code Playgroud)
请注意,循环开启array_keys($_SESSION)比循环整个$_SESSION数组更有效.
| 归档时间: |
|
| 查看次数: |
208 次 |
| 最近记录: |