简体   繁体   中英

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['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.

也许你之前没有session_start()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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