merge and sorting multiple array with average if the key is the same

Hi.

I have 2 or more arrays and i want to merge and sorting and make the average in value if the key is the same.

If the value of array_1_x exist in other arrays_x he keeps this value and is the mean of the corresponding Array_Y.
If the value of array_1_x does not exist in other arrays_x he usually keeps the value

Exemple:
1st data:
array_1_y=[0 3 6 10] y axis
array_1_x=[0 0,2 0,3 0,5] x axis

2nd data:
array_2_y=[1 56 7 10] y axis
array_2_x=[0 0,1 0,3 0,4] x axis

What i want:
array_y= [0,5 6 3 6,5 10 10]
array_x= [0 0,1 0,2 0,3 0,4 0,5]

I’m sorry for my english.

Thanks for the help :slight_smile:

Sorry for the double-post but i dont know how to edit.

I have this:
$array1 = Array(‘0’ => 0, ‘0,1’ => 10, ‘0,2’ => 15);
$array2 = Array(‘0’ => 2, ‘0,1’ => 15, ‘0,3’ => 30);

And the result:
Array ( [0] => 1 [0,1] => 12.5 [0,2] => 15 [0,3] => 30 )

If you can help me for n arrays its perfect :slight_smile:

Thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service