title: In PHP Add the duplicate values in array
body: <p>I have n number of textbox to get the name of the products and their quantity. So i used PHP array to get the value and its working fine. I tried the logic like if the user give duplicate products, then duplicate products is removed but their quantity is added with the same products.</p>
  
  <pre><code>&lt;form method="post" action ="insert.php"&gt;
  &lt;input type =text name ="products[]" value = ""&gt;
  &lt;input type =text name ="quantity[]" value = ""&gt;
  &lt;!-- ...........
  n numbers of textbox to add the products and quantity
  --------- --&gt;
  
  &lt;input type ="submit" value="submit"&gt; &lt;/form&gt;
  </code></pre>
  
  <p>insert.php:</p>
  
  <pre><code>$products = $_POST['products'];
  $quantity = $_POST['quantity'];
  for($i=0;$i&lt;count($products);$i++)
   {
  $query = "INSERT INTO table_name (`products`,`quantity`) VALUES ('$products[$i]','$quantity[$i]')";
  mysql_query($query);
  }
  </code></pre>
  
  <p>the array come like </p>
  
  <pre><code>$products[0] = "Apple"  $quantity[0] = "20"
  $products[1] = "Orange"  $quantity[1] = "10"
  $products[2] = "Apple"  $quantity[2] = "30"
  </code></pre>
  
  <p>Here products name apple is duplicate it occurs two times. So i remove the duplicate name apple and their quantity value should be added like 50(20+30)</p>