title: Removing array item from session in CakePHP
body: <p>I've added an array (shopping cart) into session. Now to remove an item from cart, I tried this logic. The cart is working fine and I can see all the items from the cart on my page. The removing logic is not giving me any error but also not removing the item from session.</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>function addToCart(){
  
      $this-&gt;layout = false;
      $this-&gt;render(false);
  
      $cart = array();
  
      $tempcart = unserialize($this-&gt;Session-&gt;read("cart")); 
  
      if(isset($tempcart)){
          $cart = $tempcart;
      }
  
      $productId = $this-&gt;request-&gt;data("id");
  
      if(!$this-&gt;existsInCart($cart, $productId)){
  
          $cart[] = array("productId" =&gt; $productId, "createdAt" =&gt; date());
  
          $this-&gt;Session-&gt;write("cart", serialize($cart));
  
          echo "added";
      }
      else
          echo "duplicate";
  }
  
  
  function removeFromCart(){
  
      $this-&gt;layout = false;
      $this-&gt;render(false);
  
      $cart = array();
  
      $tempcart = unserialize($this-&gt;Session-&gt;read("cart"));
  
      if(isset($tempcart)){
          $cart = $tempcart;
      }
  
      $productId = $this-&gt;request-&gt;data("productId");
  
      for($i=0;$i&lt;count($cart);$i++){
  
          $cartItem = $cart[$i];   //  an array
  
          if($cartItem["productId"]==$productId)
              unset($cart[$i]);
      }
  
      $this-&gt;Session-&gt;write("cart", serialize($cart));
  
      echo "removed";
  }
  </code></pre>