I have 2 Arrays, I need To Sum Array 2 values and then associate them back with array 1 value
$records_array = array('314','314','500','2100','2100','3210','2100');
$quantities_array = array('2010','1','2250','1000','1000','950','1000');
The results I need for comparative reasons
- Record: 314 Qty = 2011 (key 0, 1 are added together)
- Record: 500 Qty = 2250 (key 2 only)
- Record: 2100 Qty = 3000 (key 3, 4, 6 are added together)
- Record: 3210 Qty 950 (key 5 value)
What I do know is the array keys 0,1,2,3,4,5,6 will match record to quantity they're just in 2 different arrays.
**Just edited, find all duplicate values in records_array and add the same keys in quantities_array, then return the sum of quantities array for each records array value **
What is the best way to iterate through the arrays and return these type of results?
Thank you
for
one-liner would do it. Or you could do it with a call toarray_map
.