I have one array as this:
"4": "40000",
"5": "3000",
"6": "200",
"7": "10",
"8": "1"
I want to have an another array which adds all the bigger ones to smaller ones. I hope it makes sense. How can I achieve this?
"4": "43211",
"5": "3211",
"6": "211",
"7": "11",
"8": "1"
Just to find an efficient method so language doesn’t matter but if necessary I use php or javascript. It is an associative array so it is not sorted. And another trick is that array might or might not contain some elements. So for example “6” or “8” might be missing.
1 Answer