title: PHP Session Array not working when adding more than 2 items
body: <p>I want to add products to my array, but every time I add a product, it replaces the old one in the array.</p>
  
  <p>When I add 2 things, it works fine:</p>
  
  <pre><code>Array ( [0] =&gt; 2 [1] =&gt; 8 )
  </code></pre>
  
  <p>But when I try to add a third item or more, it replaces the second item in the array:</p>
  
  <pre><code>Array ( [0] =&gt; 2 [1] =&gt; 10 )
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>  session_start();
  
    if(isset($_POST['inCart']))
    {
         $id = $_POST['id'];
  
         if(!empty($_SESSION['cart']))
         {     
            $session = $_SESSION['cart'];
            $session[] = $id;
  
            print_r($session);
         }
  
         else
         {
            $_SESSION['cart'] = array($id); 
         }
    }
  </code></pre>