title: Removing array [0] in SESSION array error
body: <p>As a novice in this and I'm struggling with a small project.
  I’m putting together a page for INTERNAL orders in a small MTB club. My problem is if there are more than 1 order in the $_SESSION['cart']  and I try to remove the first one [0], then I get “Undefined offset: 0”.
  I get that is to do with that I remove the first entry and therefor it can’t be found when it lists the array. I just can’t see how I solve it, I have googled and tried different solutions without result.
  Please advice on how to get forward for me..
  Below code is made for this purpose only</p>
  
  <pre><code>enter code here    &lt;?php
  session_start(); 
   if(isset($_POST['submit'])){
  $total = $_POST['Amount'] * $_POST['Price'];
  $cart=array(
  'Amount'=&gt;$_POST['Amount'], //Amoun ordered of clothes
  'Size'=&gt;$_POST['Size'], //Size of clothes
  'Price'=&gt;$_POST['Price'], //Price of clothes
  'Product_id'=&gt;$_POST['Product_id'],//Id of clothes for DB
  'Product_Name'=&gt;$_POST['Product_Name'], //Name of clothes
  'Product_Total'=&gt;$total //Total price    
  );      
  $_SESSION['cart'][]=$cart;  
  }
  if(isset($_GET['Reset'])){
  unset($_SESSION['cart']);
  header('location:demo.php');
  }
  if(isset($_GET['remove'])){
  $do = $_GET['do'];      
  unset($_SESSION['cart'][$do]);
   //Redirecting After Unset SESSION
    header('location:demo.php');
    }
  ?&gt;
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Session Demo/Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;table width="590" border="4" cellspacing="0" cellpadding="5" align="center" &gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td width="373"&gt;Name of clothes&lt;/td&gt;
        &lt;td width="185"&gt;
  &lt;a href="?Reset"&gt;Reset Session&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;form method="POST"&gt;
      &lt;table width="590" border="4" cellspacing="0" cellpadding="5" align="center"&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td colspan="4" rowspan="5" align="center"&gt;&lt;img src="images/Bike_Jersy_short.jpg" width="200" height="200" alt=""/&gt;&lt;/td&gt;   
        &lt;td height="120" colspan="2"&gt; 
          Clothes description
      &lt;/td&gt;
        &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td width="112"&gt;Price:&lt;/td&gt;
        &lt;td&gt;300,00 Kr.&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;  
        &lt;td width="112"&gt;Amount:&lt;/td&gt;
        &lt;td width="116"&gt;
              &lt;input name="Amount" type="number" id="Amount" tabindex="1" value="" size="1" required &gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;  
        &lt;td&gt;Size:&lt;/td&gt;
        &lt;td&gt;
                &lt;select name="Size"  id="Size" tabindex="2" required&gt;
         &lt;option value=""&gt;&lt;/option&gt;
            &lt;option value="XS"&gt;XS&lt;/option&gt;
            &lt;option value="S"&gt;S&lt;/option&gt;
            &lt;option value="L"&gt;L&lt;/option&gt;
            &lt;option value="XL"&gt;XL&lt;/option&gt;
            &lt;option value="2XL"&gt;2XL&lt;/option&gt;
            &lt;option value="3XL"&gt;3XL&lt;/option&gt;
            &lt;option value="4XL"&gt;4XL&lt;/option&gt;
            &lt;option value="5XL"&gt;5XL&lt;/option&gt;
            &lt;option value="6XL"&gt;6XL&lt;/option&gt;
          &lt;/select&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
           &lt;tr&gt;  
        &lt;td&gt;Add:&lt;/td&gt;
        &lt;td&gt;
           &lt;input type="submit" name="submit" id="submit" value="Add"&gt;
             &lt;input name="Price" type="hidden" id="Price" value="300"&gt;
          &lt;input name="Product_id" type="hidden" id="Product_id" value="1"&gt;
            &lt;input name="Product_Name" type="hidden" id="Product_Name" value="Name of clothes"&gt;        
             &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
         &lt;/form&gt;      
  &lt;p&gt;&lt;/p&gt;
      &lt;?php
      if(empty($_SESSION['cart'])){ 
          ?&gt;
      &lt;table width="898" border="4" cellspacing="0" cellpadding="5" align="center"&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;You have no items in yet &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
      &lt;?php
      }
      else{
          ?&gt;
      &lt;table width="900" border="4" cellspacing="0" cellpadding="5" align="center"&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td width="109"&gt;Name&lt;/td&gt;
        &lt;td width="31"&gt;Amount&lt;/td&gt;
        &lt;td width="33"&gt;Size.&lt;/td&gt;
        &lt;td width="63"&gt;Price&lt;/td&gt;
        &lt;td width="55"&gt;Total&lt;/td&gt;
        &lt;td width="45"&gt;Remove&lt;/td&gt;
      &lt;/tr&gt;     
        &lt;?php for($i = 0 ; $i &lt; count($_SESSION['cart']) ; $i++) {
        ?&gt;      
      &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $_SESSION['cart'][$i]['Product_Name'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $_SESSION['cart'][$i]['Amount'];?&gt;
        &lt;/td&gt;
        &lt;td&gt;&lt;?php echo $_SESSION['cart'][$i]['Size'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $_SESSION['cart'][$i]['Price'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $_SESSION['cart'][$i]['Product_Total'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;a href="demo.php?remove=remove&amp;do=&lt;?php echo $i;?&gt;" title="Remove"&gt;Remove&lt;/a&gt;            
            &lt;?php
            }
              ?&gt;
        &lt;/td&gt;
      &lt;/tr&gt;     
      &lt;?php }  ?&gt;   
    &lt;/tbody&gt;
  &lt;/table&gt;                
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>