title: products showing up twice in php array
body: <p>Please i need help, I am creating a shopping cart feature for a cake store. when i add a product it works but if i add it again it shows up as a 2nd array. How can i make sure a product just gets added once. i used in_array() function but i don't seem to get it right.</p>
  <p>Here's my code</p>
  <pre><code> &lt;?php
  
  session_start();
  if(isset($_POST['add_to_cart']))
  {
      // if the cart isn't opened
      if(!isset($_SESSION['cart']))
      {
          $_SESSION['cart'][0]=array('cakename'=&gt;$_POST['cakename'],'cakeprice'=&gt;$_POST['cakeprice'],'Quantity'=&gt;1); 
          
          echo &quot;&lt;script&gt;
          alert('Item Added');
          window.location.href='index.php';
          &lt;/script&gt;&quot;;
      }
      // If the product already exists in the shopping cart
      elseif(in_array($_POST['cake_name'],$_SESSION['cart']))
      {
              echo &quot;&lt;script&gt;
              alert('Item ALREADY Added');
              window.location.href='index.php';
              &lt;/script&gt;&quot;;
              
      }
      else
      {
          $count= count($_SESSION['cart']);
  
          $_SESSION['cart'][$count]= array('cakename'=&gt;$_POST['cakename'],'cakeprice'=&gt;$_POST['cakeprice'],'Quantity'=&gt;1);       
          
          echo &quot;&lt;script&gt;
          alert('Item Added');
          window.location.href='index.php';
          &lt;/script&gt;&quot;;
      }         
  }
  ?&gt;
  </code></pre>