Compare two arrays (Stock inventory)
<p>For a cars company (Just an example) I need to automate the stock inventory:</p>
<blockquote>
<p>$purchase_array = array(&quot;Lamborghini&quot; =&gt; &quot;5&quot;, &quot;Ferrari&quot; =&gt; &quot;4&quot;, &quot;Bugatti&quot; =&gt; &quot;3&quot;, &quot;McLaren&quot; =&gt; &quot;2&quot;, &quot;Fiat&quot; =&gt; &quot;10&quot;, &quot;Mazda&quot; =&gt; &quot;20&quot;);</p>
<p>$sales_array = array(&quot;Lamborghini&quot; =&gt; &quot;1&quot;, &quot;Ferrari&quot; =&gt; &quot;2&quot;, &quot;Bugatti&quot;
=&gt; &quot;3&quot;);</p>
</blockquote>
<p>I want to have as results this array:</p>
<blockquote>
<p>$stock_array = array(&quot;Lamborghini&quot; =&gt; &quot;4&quot;, &quot;Ferrari&quot; =&gt; &quot;2&quot;, &quot;Bugatti&quot;
=&gt; &quot;0&quot;, &quot;McLaren&quot; =&gt; &quot;2&quot;, &quot;Fiat&quot; =&gt; &quot;10&quot;, &quot;Mazda&quot; =&gt; &quot;20&quot;);</p>
</blockquote>
<p>First I looked for the common cars:</p>
<pre><code>$common_cars = array_keys(array_intersect_key($purchase_array, $sales_array));
foreach ($common_cars as $common_car) {
.....
}
</code></pre>
<p>buy I couldn't finish it.</p>
<p>Any help will be appreciated.
Thanks in advance</p>