从codeigniter中的关联数组中取消设置键
问题描述:
How would I unset category[1]
from the below array?
Array
(
[category] => Array
(
[0] => add new
[1] => second
)
)
Can't seem to get the right code.
This is for codeigniter's session class
$this->session->unset_userdata($array['category'][$session_id]);
is the above correct? or is there something else - that's not working.
答
Assuming your array name is $array
:
unset( $array['category'][1] );
Another way is, array_pop()
array_pop( $array['category'] );
答
Is this not what you're looking for?
unset($arr['category'][1]);
答
unset( $array['category'][1] );
Assuming you know the array name.
答
I dont know what actually you are looking for , and what user_unsetdata does but i guess you want to unset the array element and you function does same than try pass by reference
$this->session->unset_userdata(&$array['category'][$session_id]);
答
You will have to do a work around hack in CI to accomplish what you want:
$SESSION = $this->session->userdata();
unset( $SESSION['category'][1] );
$this->session->set_userdata( $SESSION );