title: Join two associative array based on key using PHP
body: <p>I have two arrays here:</p>
  <pre><code>&lt;?php
      $array1 = array(
          array('id' =&gt; 1, 'name' =&gt; 'John Doe', 'age' =&gt; 20),
          array('id' =&gt; 2, 'name' =&gt; 'Mae Doe', 'age' =&gt; 17),
          array('id' =&gt; 3, 'name' =&gt; 'Mark Smith', 'age' =&gt; 35),
          array('id' =&gt; 4, 'name' =&gt; 'Selena Smith', 'age' =&gt; 15),
          array('id' =&gt; 5, 'name' =&gt; 'Shane Doe', 'age' =&gt; 26),
          array('id' =&gt; 6, 'name' =&gt; 'Will Smith', 'age' =&gt; 45)
      )
      
      $array2 = array(
          array('id' =&gt; 1, 'address' =&gt; 'Singapore'),
          array('id' =&gt; 4, 'address' =&gt; 'Japan'),
          array('id' =&gt; 5, 'address' =&gt; 'Korea')
      )
  ?&gt;
  </code></pre>
  <p>I want to join them, kind of left join in mysql so the result will be like this</p>
  <pre><code>$result = array(
      array('id' =&gt; 1,'name' =&gt; 'John Doe','age' =&gt; 20, 'address' =&gt; 'Singapore'),
      array('id' =&gt; 2,'name' =&gt; 'Mae Doe','age' =&gt; 17),
      array('id' =&gt; 3,'name' =&gt; 'Mark Smith','age' =&gt; 35),
      array('id' =&gt; 4,'name' =&gt; 'Selena Smith','age' =&gt; 15, 'address' =&gt; 'Japan'),
      array('id' =&gt; 5,'name' =&gt; 'Shane Doe','age' =&gt; 26, 'address' =&gt; 'Korea'),
      array('id' =&gt; 6,'name' =&gt; 'Will Smith','age' =&gt; 45)
  )
  </code></pre>
  <p>The address will be merged to $array1 based on the id.</p>
  <p>Is this possible using PHP? Please help. Thanks.</p>