I have items in my cart with session and I want to remove the item, my nested array is as follows,

```
[cart_items] => Array
        (
            [0] => Array
                (
                    [item_id] => 1
                    [item_name] => Neapolitan Pizza
                    [price] => 750.00
                    [toppings] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 3
                                    [name] => Chilli
                                    [price] => 100.00
                                )

                            [1] => Array
                                (
                                    [id] => 4
                                    [name] => Green chilli 
                                    [price] => 100.00
                                )

                        )

                    [quantity] => 1
                    [price_per_item] => 750
                )

            [1] => Array
                (
                    [item_id] => 16
                    [item_name] => Cheesy Garlic Bread
                    [price] => 420.00
                    [quantity] => 1
                    [price_per_item] => 420
                )

        )

```

**Controller Code:-**

In my controller, I have created the following function to `remove each item`. what am I missing here?

**/Cart/remove**

```
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']){
                    $this->session->unset_userdata($value);
                }
            }
        }
        redirect('Cart/index');

    }

```

In my view, this is how I pass the item id in the anchor tag.

**View:-**

```
<?php $list = $this->session->userdata('cart_items');
        $grand_total=0;
        if($list==Null) {
            print_r("<div><li class='list-group-item d-flex justify-content-between lh-condensed'>There are no items in the your cart</li></div>");
            $sub_total=0;
        }else{
            $sub_total=0;
            foreach ($list as $item=>$value){
                echo "<li class='list-group-item d-flex justify-content-between lh-condensed'>";
                if($value['item_id']<16) {

                    print_r("<div>" . $value['item_id'] . "</div>");
                    print_r("<div>" . $value['item_name'] . "</div>");
                    print_r("<div>" . $value['price'] . "</div>");

                    // toppings array is empty 
                    $toppings_price = 0;
                    if ($value['toppings'] == null) {
                        print_r("<div>No toppings selected</div>");
                    } else {
                        foreach ($value['toppings'] as $val) {
                            // printing topping names
                            print_r("");
                            print_r($val['name']);
                            print_r(",");
                            $toppings_price = $toppings_price + $val['price'];
                        }
                    }

                }else{
                    print_r("<div>" . $value['item_id'] . "</div>");
                    print_r("<div>" . $value['item_name'] . "</div>");
                    print_r("<div>" . $value['price'] . "</div>");
                }

                print_r("<div>".$value['quantity']."</div>");
                print_r("<div><a href='".base_url()."index.php/Cart/remove/".$value['item_id']."' class='btn btn-danger'>Remove</a></div>");
                echo "</li>";

                //sub total
                if($value['item_id']<16){
                    $sub_total+=($value['price']*$value['quantity'])+$toppings_price;
                }else{
                    $sub_total+=($value['price']*$value['quantity']);
                }
            }
        }
        $grand_total = $sub_total;
        ?>

```

When i clicked on the "remove" button it loads to the same page but item row doesn't get removed.