Let's say I have this array
$number = [2,1,4,3,6,2];
-
First pair the elements on an array by two's and find their difference so this is the output in the first requirement
$diff[] = [1,1,4];
-
Second sum all the difference this is the final output
$sum[] = [6];
Conditions:
- the array size is always even
- the first element in a pair is always greater than the second one, so their is no negative difference
What I've done so far is just counting the size of an array then after that I don't know how to pair them by two's. T_T
Is this possible in php? Is there a built in function to do it?