Welcome Guest, Not a member yet? Register   Sign In
Unset Session Array Using Key
#1

[eluser]Amit Patel[/eluser]
Hello All,

I want to unset the key from multidimensional array in session so how can i do this using CI function


Code:
Array
(
    [session_id] => aeb17c3ed9963ca7af58af0339e42828
    [ip_address] => 192.168.10.58
    [user_agent] => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7
    [last_activity] => 1237621023
    [childCompanyId] => Array
        (
            [6] => Test
            [8] => Test123
            [10] => Test14
            [9] => Test988
        )

)

I tried to use $this->session->unset_userdata('childCompanyId['.$this->childCompanyId.']');

where child company ID is 6 or 8 or 10 or 9 etc.

But it's not working.

So how can i unset this key from array ..

Please help me
#2

[eluser]boudewijn[/eluser]
I'd like to know aswell!
#3

[eluser]Dam1an[/eluser]
As far as I'm aware, and there have been a few threads regarding arrays in sessions, and this is the general view on them

Its possible to store and retreive arrays from sessions, but to get a single value/manipulate them you need the whole array

So you could do something like
Code:
$array = $this->session->userdata('childCompanyID');
$this->session->unset_userdata('childCompanyID');
unset($array['1']);
$this->session->set_userdata('childCompanyID', $array);

You could extend the session class and add this functionality if you want in a function
#4

[eluser]Thorpe Obazee[/eluser]
The same way I did mine. I haven't found any other way.




Theme © iAndrew 2016 - Forum software by © MyBB