title: PHP Combine Associative Arrays If Specific Key Matches Inside For-Loop
body: <p>I am working to combine 2 different arrays based on the comparison of a key if the values match, otherwise the combine does not occur.</p>
  
  <p>Here is a short example of each array to begin with, however both array could be about 1,000 items:</p>
  
  <pre><code>Vehicle Array
  (
    [vehicle] =&gt; 2016 Ford Transit 250 Cargo Van
    [stockno] =&gt; 153721
    [msrp] =&gt; 32195
    [price] =&gt; 32195
    [payment] =&gt; 359
    [type] =&gt; New
    [bodystyle] =&gt; Van
    [mileage] =&gt; 6
    [year] =&gt; 2016
    [make] =&gt; Ford
    [model] =&gt; Transit 250
    [trim] =&gt; Cargo Van
  ),(
    [vehicle] =&gt; 2016 Ford F150 XLT
    [stockno] =&gt; 153723
    [msrp] =&gt; 36195
    [price] =&gt; 36195
    [payment] =&gt; 429
    [type] =&gt; New
    [bodystyle] =&gt; Truck
    [mileage] =&gt; 6
    [year] =&gt; 2016
    [make] =&gt; Ford
    [model] =&gt; F150
    [trim] =&gt; XLT
  )
  
  Special Array
  (
    [vehicle] =&gt; 2016 Ford Transit 250 Cargo Van
    [store] =&gt; Baxter Ford
    [offertype] =&gt; $ Off MSRP
    [offervalue] =&gt; Up to $10,000
    [disclaimer] =&gt; *Valid on in-stock models. Based on stock #161621. Tax, title and license extra. With approved credit. Includes hail sale savings. See dealer for details. Offer expires 8\/1\/16.
    [expires] =&gt; 8/1/16
  ),(
    [vehicle] =&gt; 2016 Ford Mustang Premium
    [store] =&gt; Baxter Ford
    [offertype] =&gt; $ Off MSRP
    [offervalue] =&gt; Up to $4,000
    [disclaimer] =&gt; *Valid on in-stock models. Based on stock #163421. Tax, title and license extra. With approved credit. Includes hail sale savings. See dealer for details. Offer expires 8\/1\/16.
    [expires] =&gt; 8/1/16
  )
  </code></pre>
  
  <p>The goal is to combine on Vehicle Array[vehicle] and Special Array[vehicle] to create an array like this:</p>
  
  <pre><code>Combined Array
  (
    [vehicle] =&gt; 2016 Ford Transit 250 Cargo Van
    [stockno] =&gt; 153721
    [msrp] =&gt; 32195
    [price] =&gt; 32195
    [payment] =&gt; 359
    [type] =&gt; New
    [bodystyle] =&gt; Van
    [mileage] =&gt; 6
    [year] =&gt; 2016
    [make] =&gt; Ford
    [model] =&gt; Transit 250
    [trim] =&gt; Cargo Van
    [store] =&gt; Baxter Ford
    [offertype] =&gt; $ Off MSRP
    [offervalue] =&gt; Up to $10,000
    [disclaimer] =&gt; *Valid on in-stock models. Based on stock #161621. Tax, title and license extra. With approved credit. Includes hail sale savings. See dealer for details. Offer expires 8\/1\/16.
    [expires] =&gt; 8/1/16
  ),(
    [vehicle] =&gt; 2016 Ford F150 XLT
    [stockno] =&gt; 153723
    [msrp] =&gt; 36195
    [price] =&gt; 36195
    [payment] =&gt; 429
    [type] =&gt; New
    [bodystyle] =&gt; Truck
    [mileage] =&gt; 6
    [year] =&gt; 2016
    [make] =&gt; Ford
    [model] =&gt; F150
    [trim] =&gt; XLT
  )
  </code></pre>
  
  <p>This seems extremely simple, but I seem to missing something. I have attempted this with a nested foreach like so:</p>
  
  <pre><code>foreach ($vehicleArr as $v) {
    foreach ($specialArr as $s) {
      if ($v['vehicle'] === $s['vehicle']) {
        $freshArr[] = array_merge($v, $s);
      } else {
        $freshArr[] = $v;
      }
    }
  }
  </code></pre>
  
  <p>This creates a massive memory leak and kills the script.</p>
  
  <p>Thanks in advance.</p>