title: PHP Sessions shopping cart: update product if it's already id the session
body: <p>I have struggled to find a solution to a simple shopping cart with <code>$_SESSION</code>. 
  I kept it very simple and this is my code right now</p>
  
  <pre><code>if ( Input::isPost('add') ) {
  
      $id = Input::get('id');
      $qta = Input::post('qta');
      $size = Input::post('size');
  
      if ( !isset($_SESSION['cart']) ) {
          $_SESSION['cart'] = array();
      }
  
      if ( array_key_exists($id, $_SESSION['cart']) ) {
          if ( $_SESSION['cart'][$id][0] == $size ) {
              $_SESSION['cart'][$id][1]+=$qta;
          } else {
              $_SESSION['cart'][$id] = array( $size, $qta );
          }
      } else {
          $_SESSION['cart'][$id] = array( $size, $qta );
      }
  
  }
  </code></pre>
  
  <p>So, what this code does ?</p>
  
  <p>1) If the <code>$_SESSION['cart']</code> does not exist, create it, otherwise add the new item.  2)When you add to cart a item, you must choose a size and a quantity for that item.  3) If that item already exists in the cart array, check if the size is the same, if so just update the quantity. Here is the problem, if the item already exists(checks for the <code>$_SESSION['cart'][$id]</code>) BUT the size is different, do not update the current one, but instead create a new item. The problem is that the current one is being replaced instead of adding one, so instead of 2 products with the same <code>id</code> but different <code>size</code>, I only have the most recent one.</p>
  
  <p>If you could help me solve it I'll be very thankful !</p>
  
  <p>Thank you in advance. </p>