CodeIgniter Forums

Full Version: unset session data (inside user_data array)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
So I have a 'cart' array inside my session like this

Code:
Array
(
[session_id] => 4a5a5dca22728fb0a84364eeb405b601
[ip_address] => 127.0.0.1
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7;
[last_activity] => 1303142623
[cart] => Array( [1]=1;
                           [2]=3;
                )
)
My question, I want to unset one of the id inside cart array..but not the whole 'cart' data

Code:
$this->session->unset_userdata($id); //$id as in [cart][$id]
//or even like this below
$tmp = $this->session->userdata('cart');          
$this->session->unset_userdata($tmp[$pid]);
I tried the above, but it doesn't do a thing. Help!

So basically I need something like:
Code:
unset($_SESSION['cart'][$id]);
as in pure php code

PS: I pass the $id through uri and can echo the $id just fine. I'm not using CI built in shopping cart class as the client has other custom requirement.