简体   繁体   English

如何取消设置PHP中的数组_SESSION变量

[英]How to unset a _SESSION Variable that is an Array in PHP

I have a certain session variable that is actually an array. 我有一个特定的会话变量,实际上是一个数组。 I want to delete the entire array variable but cannot make it happen. 我想删除整个数组变量但不能实现它。

_SESSION VAR _SESSION VAR

$_SESSION['auth']['id']
$_SESSION['auth']['username']
$_SESSION['auth']['role']

I tried unset($_SESSION['auth']) but it does not work. 我尝试unset($_SESSION['auth'])但它不起作用。 Do I need to unset each 2nd level array individually using unset()? 我是否需要使用unset()单独取消设置每个第二级数组?

Thanks. 谢谢。

也许你之前没有session_start()

unset should be working :S As Artjom Kurapov also pointed out, it might have to due with the session not being started. 未设置应该正常工作:S正如Artjom Kurapov所指出的那样,它可能不得不在会议期间开始。

But anyhow, have you tried just doing 但无论如何,你有没有尝试过

$_SESSION['auth'] = array();

Or if you don't care about the session at all, you could do session_unset or session_destroy 或者,如果您根本不关心会话,则可以执行session_unsetsession_destroy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM