So I would like to subtract stocks
from $array1
and quantity
from $array2
,
$array1= ([product_id]=>4, [stocks]=>20)
$array2= ([product_id]=>4, [quantity]=>3)
So that would be:
$array1= ([0]=> 4, [1] => 20);
$array2= ([0]=> 4, [1] => 3);
And then the output should be:
$array1= ([0]=> 4, [1] => 17);
Need your help guys..
$total = $array1['stocks'] - $array2['quantity']
– Marc B Oct 22 '13 at 19:07array_diff()
but it only returns one element, I really new to this kind of array manipulation :( – Juan D Jensen Oct 22 '13 at 19:08array_diff()
isn't actually used for mathematical calculation between arrays. What it does is looks for elements that aren't common between multiple arrays and returns a new array of those elements. I think in your case a loop implementation will be best. Something that looks at array keys and then does the proper math. – Crackertastic Oct 22 '13 at 19:12