3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array ( "0" => Array ( "2" => 123 ), "1" => Array ( "4" => 45 ), "2" => Array ( "3" => 12 ), "3" => Array ( "5" => 2 ), "4" => Array ( "2" => 12 ), "5" => Array ( "4" => 21 ), "6" => Array ( "2" => 12 ), "7" => Array ( "3" => 21 ), "8" => Array ( "2" => 12 ), "9" => Array ( "3" => 21 ), "10" => Array ( "2" => 2 ), "11" => Array ( "4" => 2 ), "12" => Array ( "2" => 2 ), "13" => Array ( "4" => 2 ), "14" => Array ( "3" => 12 ), "15" => Array ( "4" => 12 ), "16" => Array ( "2" => 12 ), "17" => Array ( "2" => 12 ), "18" => Array ( "4" => 12 ), "19" => Array ( "3" => 12 ), "20" => Array ( "2" => 15 ), "21" => Array ( "4" => 21 ), ); // find all subarray keys (2,3,4,5) foreach($arr as $subarr){ $keys[] = key($subarr); } // remove duplicate keys $keys = array_unique($keys); // sum values with same key from $arr and save to $sums foreach($keys as $key){ $sums[$key] = array_sum(array_column($arr,$key)); } var_dump($sums);
Output for git.master, git.master_jit, rfc.property-hooks
array(4) { [2]=> int(202) [4]=> int(115) [3]=> int(78) [5]=> int(2) }

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:
110.33 ms | 405 KiB | 5 Q