php 在 codeigniter 中取消设置一些会话数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7969089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unsetting some session data in codeigniter
提问by Udders
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,
print_r($this->session->userdata('shortlist');
这给我留下了以下输出,
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]);
unset($this->session->userdata('shortlist')[0]);
回答by Vikk
You can use this:
你可以使用这个:
$this->session->unset_userdata('some_name');
For more info:
欲了解更多信息:
http://codeigniter.com/user_guide/libraries/sessions.html
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);