I have two multidimensional arrays which store x and y coordinates I am trying to merge together into a single array while preserving the x value but adding together the y values.
Array 1:
Array(
[0] => Array
(
[x] => 1327449600000
[y] => 5
)
[1] => Array
(
[x] => 1327450500000
[y] => 1
)
Array 2:
Array(
[0] => Array
(
[x] => 1327449600000
[y] => 1
)
[1] => Array
(
[x] => 1327450500000
[y] => 3
)
So the combined outcome would be:
Array(
[0] => Array
(
[x] => 1327449600000
[y] => 6
)
[1] => Array
(
[x] => 1327450500000
[y] => 4
)
Any help would be greatly appreciated.
Each of your original arrays is a vector; let's allow them to contain an arbitrary amount of points (of any dimension):
EDIT:
I just realized you were writing PHP. Give me a sec to convert the code please.