数组运算

gok*_*gok 0 arrays math

我有一个数组:

  "4": "40000",
  "5": "3000",
  "6": "200",
  "7": "10",
  "8": "1"
Run Code Online (Sandbox Code Playgroud)

我想要另一个数组,将所有较大的数组添加到较小的数组中.我希望这是有道理的.我怎样才能做到这一点?

  "4": "43211",
  "5": "3211",
  "6": "211",
  "7": "11",
  "8": "1"
Run Code Online (Sandbox Code Playgroud)

只是找到一个有效的方法,所以语言无关紧要,但如果有必要,我使用PHP或JavaScript.它是一个关联数组,因此不进行排序.另一个技巧是数组可能包含也可能不包含某些元素.因此,例如"6"或"8"可能会丢失.

spr*_*aff 5

for i = 7 to 4 decreasing
    array [i] += array [i+1]
Run Code Online (Sandbox Code Playgroud)