title: Merging two multidimensional arrays on specific key
body: <p>Let's say I have following arrays:</p>
  
  <pre><code>Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 5
                  [name] =&gt; Education
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 4
                  [name] =&gt; Computers
              )
  
          [3] =&gt; Array
              (
                  [id] =&gt; 7
                  [name] =&gt; Science
  
          [4] =&gt; Array
              (
                  [id] =&gt; 1
                  [name] =&gt; Sports
              )
      )
  </code></pre>
  
  <p>And the second one:</p>
  
  <pre><code>Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 1
                  [title] =&gt; Sport
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 7
                  [title] =&gt; Sci
              )
  
          [3] =&gt; Array
              (
                  [id] =&gt; 4
                  [title] =&gt; Comp
  
          [4] =&gt; Array
              (
                  [id] =&gt; 5
                  [title] =&gt; Edu
              )
      )
  </code></pre>
  
  <p>And desired output is:</p>
  
  <pre><code>Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 5
                  [name] =&gt; Education
                  [title] =&gt; Edu
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 4
                  [name] =&gt; Computers
                  [title] =&gt; Comp
              )
  
          [3] =&gt; Array
              (
                  [id] =&gt; 7
                  [name] =&gt; Science
                  [title] =&gt; Sci
  
          [4] =&gt; Array
              (
                  [id] =&gt; 1
                  [name] =&gt; Sports
                  [title] =&gt; Sport
              )
      )
  </code></pre>
  
  <p>I have managed to merge these arrays with simply:</p>
  
  <pre><code>foreach($first as $key =&gt; $value){
      $result[$key] = array_merge($first[$key], $second[$key]);
  }
  </code></pre>
  
  <p>But the output is not combined correctly:</p>
  
  <pre><code>Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 5
                  [name] =&gt; Education
                  [title] =&gt; Sport
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 4
                  [name] =&gt; Computers
                  [title] =&gt; Sci
              )
  
          [3] =&gt; Array
              (
                  [id] =&gt; 7
                  [name] =&gt; Science
                  [title] =&gt; Comp
  
          [4] =&gt; Array
              (
                  [id] =&gt; 1
                  [name] =&gt; Sports
                  [title] =&gt; Edu
              )
      )
  </code></pre>
  
  <p>The problem is I would like to merge these arrays on the same <code>id</code>. 
  Desired output sorting should be same as in the first array.</p>
  
  <p>How can I achieve this? Any help is much appreciated.</p>