title: php shopping cart session id remove
body: <p>if have session cart items more than 1 its not work.. but its have only one its work. what happen for this</p>
  
  <p>I put my all of codes in session. check what happen for this case...</p>
  
  <p>here is my php code for this link <code>?action=remove&amp;id=&lt;value&gt;</code></p>
  
  <pre><code>function checkCartForItem($addItem, $cartItems) {
       if (is_array($cartItems)){
            foreach($cartItems as $key =&gt; $item) {
                if($item['id'] === $addItem)
                    return $key;
            }
       }
       return false;
  }
  
  if (!empty($_GET['qty'])) {
  
      $qty = $_GET['qty'];
  }
  
  //Store it in a Array
  $ITEM = array(
  //Item name     
  'id' =&gt; $_POST['id']    
  
  );
  
  $addItem = $_GET['id'];
  
  
  //check
  if(!empty($_GET["action"])) {
  switch($_GET["action"]) {
      case "add":
          if(!empty($_GET["qty"])) {
  
              $productByCode = $db_handle-&gt;runQuery("SELECT * FROM product WHERE id='" . $_GET["id"] . "'");
              $itemArray = array($productByCode[0]["id"]=&gt;array('name'=&gt;$productByCode[0]["product_name"], 'id'=&gt;$productByCode[0]["id"], 'quantity'=&gt;$qty, 'price'=&gt;$productByCode[0]["new_price"]));
  
              $itemExists = checkCartForItem($addItem, $_SESSION['cart_item']); 
  
              if ($itemExists !== false){  
                  $_SESSION['cart_item'][$itemExists]['quantity'] = $qty ; 
              } else { 
  
                  if(!empty($_SESSION["cart_item"])) {
  
                      if(in_array($productByCode[0]["id"],$_SESSION["cart_item"])) {
                          foreach($_SESSION["cart_item"] as $k =&gt; $v) {
                                  if($productByCode[0]["id"] == $k)
                                      $_SESSION["cart_item"][$k]["quantity"] = $qty;
                          }
                      } else {
                          $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
                      }
                  } else {
                      $_SESSION["cart_item"] = $itemArray;
                  }   
              } 
          }
      break;
      case "remove":
          if(!empty($_SESSION["cart_item"])) {
              foreach($_SESSION["cart_item"] as $k =&gt; $v) {
                      if($_GET["id"] == $k)
                          unset($_SESSION["cart_item"][$k]);      
                      if(empty($_SESSION["cart_item"]))
                          unset($_SESSION["cart_item"]);
              }
          }
  
      break;
      case "empty":
          unset($_SESSION["cart_item"]);
      break;  
  }
  }
  </code></pre>
  
  <p>array (<code>print_r($_SESSION["cart_item"]);</code>)</p>
  
  <pre><code>Array ( [0] =&gt; Array ( [name] =&gt; Sadfsafsadf [id] =&gt; 11 [quantity] =&gt; 1 [price] =&gt; safsafsa ) [1] =&gt; Array ( [name] =&gt; TP-LINK 4 Port Wireless Dual Band N600 [id] =&gt; 13 [quantity] =&gt; 1 [price] =&gt; 15980 ) )
  </code></pre>