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

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

问题描述:

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['auth']['id']
$_SESSION['auth']['username']
$_SESSION['auth']['role']

I tried unset($_SESSION['auth']) but it does not work. Do I need to unset each 2nd level array individually using unset()?

Thanks.

我有一个实际上是一个数组的会话变量。 我想删除整个数组变量但不能实现它。 p>

_SESSION VAR strong> p>

  $ _ SESSION  [ 'AUTH'] [ 'ID'] 
上$ _SESSION [ 'AUTH'] [ '用户名'] 
上$ _SESSION [ 'AUTH'] [ '角色'] 
上代码>  PRE> 
  
 

我尝试了 unset($ _ SESSION ['auth']) code>但它不起作用。 我是否需要使用unset()单独取消设置每个第二级数组? p>

谢谢。 p> div>

unset should be working :S As Artjom Kurapov also pointed out, it might have to due with the session not being started.

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

Maybe you don't have session_start() somewhere before?