title: Merge php array with dynamic key
body: <p>If I query out the array like this form:</p>
  
  <pre><code>$arr1:
  
  0 =&gt; 
        'id' =&gt; 1,
        'name' =&gt; 'a'
  1 =&gt; 
       'id' =&gt; 2,
       'name' =&gt; 'b'
  2 =&gt; 
       'id' =&gt; 3,
       'name' =&gt; 'c'
  3 =&gt; 
       'id' =&gt; 4,
       'name' =&gt; 'd'
  </code></pre>
  
  <pre><code>$arr2:
  
  0 =&gt; 
        'id' =&gt; 1,
        'parent' =&gt; '1a'
  1 =&gt; 
       'id' =&gt; 2,
       'parent' =&gt; '2b'
  2 =&gt; 
       'id' =&gt; 3,
       'parent' =&gt; '3c'
  3 =&gt; 
       'id' =&gt; 4,
       'parent' =&gt; '4d'
  </code></pre>
  
  <p>When I need to merge these two I can done it using <code>foreach loop</code>.</p>
  
  <p>The problem comes to when the <code>$arr1</code> is <code>dynamic data</code>(<strong>need to use for pagination</strong>), i can't merge well using array_merge due to <code>$arr2</code> is fixed data.</p>
  
  <p>example: 
  first time:</p>
  
  <pre><code>$arr1:
  0 =&gt; 
        'id' =&gt; 1,
        'name' =&gt; 'a'
  1 =&gt; 
       'id' =&gt; 2,
       'name' =&gt; 'b'
  </code></pre>
  
  <pre><code>$arr2:
  
  0 =&gt; 
        'id' =&gt; 1,
        'parent' =&gt; '1a'
  1 =&gt; 
       'id' =&gt; 2,
       'parent' =&gt; '2b'
  2 =&gt; 
       'id' =&gt; 3,
       'parent' =&gt; '3c'
  3 =&gt; 
       'id' =&gt; 4,
       'parent' =&gt; '4d'
  </code></pre>
  
  <p>second time:</p>
  
  <pre><code>$arr1:
  0 =&gt; 
        'id' =&gt; 3,
        'name' =&gt; 'c'
  1 =&gt; 
       'id' =&gt; 4,
       'name' =&gt; 'd'
  </code></pre>
  
  <pre><code>$arr2:
  
  0 =&gt; 
        'id' =&gt; 1,
        'parent' =&gt; '1a'
  1 =&gt; 
       'id' =&gt; 2,
       'parent' =&gt; '2b'
  2 =&gt; 
       'id' =&gt; 3,
       'parent' =&gt; '3c'
  3 =&gt; 
       'id' =&gt; 4,
       'parent' =&gt; '4d'
  </code></pre>
  
  <p>I had try using <code>foreach loop</code></p>
  
  <pre><code>foreach($arr1 as $k =&gt; $value){
    $group[$k]['parent'] = $arr2[$k]['parent'];
    $group[$k]['name'] = $value['name'];
    $group[$k]['id'] = $value['id'];
  }
  </code></pre>
  
  <p>It comes to the parent value does not change as <code>$key</code> is fixed.</p>
  
  <p>The expected output should all the element in <strong>1 array</strong>:</p>
  
  <pre><code>0 =&gt; 
        'id' =&gt; 1,
        'parent' =&gt; '1a'
        'name'='a'
  1 =&gt; 
       'id' =&gt; 2,
       'parent' =&gt; '2b'
       'name'='b'
  
  </code></pre>