Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 PHP 设置所有以 cont_ 开头的会话变量,所以$_SESSION['cont_......现在我不能使用$_SESSION['cont']['subvariable'];与服务器相关的特定原因。我试过这样做unset($_SESSION['cont_'*];,但这会给出错误。
$_SESSION['cont_
$_SESSION['cont']['subvariable'];
unset($_SESSION['cont_'*];
最好的方法是无需设置即可做到这一点$_SESSION['cont']['var'];?
$_SESSION['cont']['var'];
提前非常感谢!
foreach($_SESSION as $key => $val){ if(substr($key,0,5) === "cont_"){ unset($_SESSION[$key]); } }
您必须遍历数组,找到以开头的数组cont_并取消设置。
cont_
foreach ($_SESSION as $key => $val) { if (preg_match('/$cont_/', $key)) { unset($_SESSION[$key]); } }