title: How to merge two arrays diferents on one
body: <p>How to update an array of objects, adding the quantities if you already have the same ID, or if you have not created a new object.</p>
  <p>I tried to explain in the code with the arrays and also with the idea of how I would like the result to be.</p>
  <p>old Array</p>
  <pre><code>$a1 = [
      array(
          &quot;id&quot; =&gt; 1,
          &quot;qty&quot; =&gt; 1
      ),
      array(
          &quot;id&quot; =&gt; 2,
          &quot;qty&quot; =&gt; 1
      )
  ];
  
  $a2 = [
      array(
          &quot;id&quot; =&gt; 1,
          &quot;qty&quot; =&gt; 1
      )
  ];
  
  $output = array_merge($a1, $a2);
  
  echo '&lt;pre&gt;';
  print_r($output);
  echo '&lt;/pre&gt;';
  </code></pre>
  <p>Result Error:</p>
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [id] =&gt; 1
              [qty] =&gt; 1
          )
  
      [1] =&gt; Array
          (
              [id] =&gt; 2
              [qty] =&gt; 1
          )
  
      [2] =&gt; Array
          (
              [id] =&gt; 1
              [qty] =&gt; 1
          )
  
  )
  </code></pre>
  <p>What I need, in addition to if the ID does not contain, add.</p>
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [id] =&gt; 1
              [qty] =&gt; 2
          )
  
      [1] =&gt; Array
          (
              [id] =&gt; 2
              [qty] =&gt; 1
          )   
  )
  </code></pre>