unsetting some session data in codeigniter
Asked Answered
G

1

6

I am saving some data in a session, and certain points in my websites, I am giving the user the option to removes certain parts of the session based on the array key, the array I get when I do,

print_r($this->session->userdata('shortlist'); this leaves me the the following output,

Array ( [0] => Array ( 
    [id] => 40 
    [name] => Namey Name 
    [location] => location is a place 
    [talent] => voice over 
    [image] => ./media/uploads/headshots/width_60_249613_10150280293315435_717615434_9570480_8341358_n.jpg ) );

How can I remove this from my shortlist session? I have tried doing the following, but to no avail,

unset($this->session->userdata('shortlist')[0]);

Guidepost answered 1/11, 2011 at 15:53 Comment(0)
M
14

You can use this:

$this->session->unset_userdata('some_name');

For more info:

http://codeigniter.com/user_guide/libraries/sessions.html

EDIT: After comment: You can do something like this-

$shortlist = $this->session->userdata('shortlist');
unset($shortlist[0]);
$this->session->set_userdata('shortlist',$shortlist);
Milkandwater answered 1/11, 2011 at 15:58 Comment(1)
that would unset the entire shortlist entry of my session though, I only want to unset specific array within it.Guidepost

© 2022 - 2024 — McMap. All rights reserved.