3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{ "thn": "2017", "jumlah": "30" }, { "thn": "2018", "jumlah": "80" }, { "thn": "2018", "jumlah": "64" }, { "thn": "2018", "jumlah": "5" }, { "thn": "2018", "jumlah": "1" }, { "thn": "2018", "jumlah": "1" }, { "thn": "2018", "jumlah": "4" }, { "thn": "2018", "jumlah": "5" }, { "thn": "2018", "jumlah": "198" }, { "thn": "2018", "jumlah": "2" }, { "thn": "2018", "jumlah": "202" }, { "thn": "2019", "jumlah": "31" }, { "thn": "2019", "jumlah": "1" }]'; $array = json_decode($json,true); $finalArray = array(); foreach($array as $arr){ $finalArray[$arr['thn']]['jumlah'] = (isset($finalArray[$arr['thn']]['jumlah']) ? $finalArray[$arr['thn']]['jumlah'] + $arr['jumlah']: $arr['jumlah']); $finalArray[$arr['thn']]['thn'] = $arr['thn']; } $finalArray = array_values($finalArray); echo json_encode($finalArray);
Output for git.master, git.master_jit, rfc.property-hooks
[{"jumlah":"30","thn":"2017"},{"jumlah":562,"thn":"2018"},{"jumlah":32,"thn":"2019"}]

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
42.82 ms | 401 KiB | 8 Q