title: PHP merge two arrays with matching values based on key
body: <p>I have two arrays; the first one has a set of instructions to delete what post from the second array.</p>
  
  <p><strong>The First Array</strong></p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [post_delete] =&gt; 1
              [post_key] =&gt; YXdsrP
          )
  
      [1] =&gt; Array
          (
              [post_delete] =&gt; 1
              [post_key] =&gt; 1jV37Q
          )
  
      [2] =&gt; Array
          (
              [post_delete] =&gt; 1
              [post_key] =&gt; JvlMIL
          )
  )
  </code></pre>
  
  <p><strong>The Second Array</strong></p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [post_id] =&gt; 598490e010c7c25738677bd0
              [post_key] =&gt; TbjI1A
          )
  
      [1] =&gt; Array
          (
              [post_id] =&gt; 598490c210c7c24938677bd1
              [post_key] =&gt; YXdsrP
          )
  
      [2] =&gt; Array
          (
              [post_id] =&gt; 598490a41908cd2619677bd0
              [post_key] =&gt; myYIKh
          )
  
      [3] =&gt; Array
          (
              [post_id] =&gt; 59847e2a10c7c2155ff80e82
              [post_key] =&gt; 1jV37Q
          )
  
      [4] =&gt; Array
          (
              [post_id] =&gt; 59847e076bf29fec56f274c2
              [post_key] =&gt; JvlMIL
          )
  )
  </code></pre>
  
  <p>I am looking to combine these two arrays and create one based on matching the keys labeled "post_key" within each array, while dropping the others from the second array. The end result I am looking for.</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [post_delete] =&gt; 1
              [post_key] =&gt; YXdsrP
              [post_id] =&gt; 598490c210c7c24938677bd1
          )
  
      [1] =&gt; Array
          (
              [post_delete] =&gt; 1
              [post_key] =&gt; 1jV37Q
              [post_id] =&gt; 59847e2a10c7c2155ff80e82
          )
  
      [2] =&gt; Array
          (
              [post_delete] =&gt; 1
              [post_key] =&gt; JvlMIL
              [post_id] =&gt; 59847e076bf29fec56f274c2
          )
  )
  </code></pre>