That’s because your userdata is not the values themselves but the array containing them. You need to remove the item from the array and then save the array as the new userdata. Try something like this:
public function remove($id){
$this->load->library('session');
$list = $this->session->userdata('cart_items');
if($list){
foreach ($list as $item=>$value){
if($id==$value['item_id']){
unset($list[$item]);
$list = array_values($list); // optional, reindex the array.
break;
}
}
$this->session->set_userdata('cart_items', $list);
}
redirect('Cart/index');
}
CLICK HERE to find out more related problems solutions.