Let's say I have 2 same sized arrays filled with values. The dates array contains dates in string format and the costs array contains numeric costs. For instance:
$dates = array('2001-01-01', '2001-02-01', '2001-02-01', '2001-02-01', '2001-03-01', '2001-04-01', '2001-04-01', '2001-05-01');
$costs = array(5, 10, 20, 4, 30, 14, 2, 0);
What I want is to sum the numbers from the costs array into a new array only when the dates in the $dates array are repeated. When this happens, the new array value must be a sum of its "left siblings".The rest new array value(s) should be 0. In other case (when the date is unique in the array, then the new array value is 0).
This should be the result of the above proccess:
$newarr = array(5, 0, 0, 34, 30, 0, 16, 0);