3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr = array( array('num'=>5,'period'=>3), array('num'=>10,'period'=>3), array('num'=>15,'period'=>9) ); $temp = array(); foreach($arr as $item) { list($n, $p) = array_values($item);print_r($p);print_r($n); $temp[$p] = array_key_exists($p, $temp) ? $temp[$p]+$n : $n; } print_r($temp); $arr = array(); foreach($temp as $p => $n) $arr[] = array('num'=>$n, 'period'=>$p); print_r($arr);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
35310915Array ( [3] => 15 [9] => 15 ) Array ( [0] => Array ( [num] => 15 [period] => 3 ) [1] => Array ( [num] => 15 [period] => 9 ) )