title: How to combine 2 associative arrays in php such that we do not overwrite any duplicate entries in all cases?
body: <p>I have two associative array which have many content same and so I want to combine those two arrays in such a way that if I have <code>a</code> in array 1 and <code>a</code> in array 2 than in array 3 I should have entries for both <code>a's</code> and not 1.</p>
  
  <p>I have tried using array_merge but it would overwrite entries in 1st array if there are any duplicates in 2nd array, I have also tried using <code>+</code> but it gives me fatal error saying <code>Fatal error: Unsupported operand types in /home/code.php</code> then I tried doing</p>
  
  <p><code>(array)$ar3 = (array)$ar1 +(array)$ar2</code> and it seems to add up. I want to know is this the correct way to do it and also why did initially I got fatal error and than it worked as I had already defined $ar3, $ar2, $ar1 as array types. </p>
  
  <pre><code>$orders = new Order(); 
  $prospectOffers = $orders-&gt;getOrder($orderConfNumber); 
  $prospectOffersResult = json_decode($prospectOffers,true); 
  $shoppingBasket = $cart-&gt;getCartItems(); 
  var_dump($prospectOffersResult); // Both are arrays 
  var_dump($shoppingBasket); //Both are arrays 
  (array)$result = (array)$prospectOffersResult+(array)$shoppingBasket;
  </code></pre>
  
  <p>Thanks. </p>