title: PHP: Combine two arrays keeping duplicate keys?
body: <p>How do I combine two arrays where the first array contains duplicate keys? e.g. combine the following:</p>
  
  <pre><code>$keys_arr
  Array
      (
          [0] =&gt; iPhone
          [1] =&gt; iPhone
          [2] =&gt; iPhone
          [3] =&gt; Samsung
      )
  
  $values_arr
  Array
  (
      [0] =&gt; 5
      [1] =&gt; 5
      [2] =&gt; 5
      [3] =&gt; Galaxy IV
  )
  </code></pre>
  
  <p>The result I'm looking for is:</p>
  
  <pre><code>$combined_array
  Array
      (
          [iPhone] =&gt; 5
          [iPhone] =&gt; 5
          [iPhone] =&gt; 5
          [Samsung] =&gt; Galaxy IV
      )
  </code></pre>
  
  <p>Using the following foreach (<a href="https://stackoverflow.com/questions/9078770/php-merge-two-arrays-similar-to-array-combine-but-with-duplicate-keys">PHP - merge two arrays similar to array_combine, but with duplicate keys</a>):</p>
  
  <pre><code>foreach ($keys_arr as $key =&gt; $value) {
      $combined_array[] = array($value =&gt; $values_arr[$key]);
  }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [iPhone] =&gt; 5
          )
  
      [1] =&gt; Array
          (
              [iPhone] =&gt; 5
          )
  
      [2] =&gt; Array
          (
              [iPhone] =&gt; 5
          )
  
      [3] =&gt; Array
          (
              [Samsung] =&gt; Galaxy IV
          )
  
  )
  </code></pre>
  
  <p>Where am I going wrong?</p>