3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = array( 0 => array( 2 => array( "type" => 1, "score" => 10, ), ), 1 => array( 2 => array( "type" => 2, "score" => 5, ), ), 2 => array( 2 => array( "type" => 3, "score" => 4, ), ), 3 => array( 2 => array( "type" => 4, "score" => 60, ), ), 4 => array( 1 => array( "type" => 1, "score" => 5, ), ), ); $array2 = array(0 => 2, 1 => 1); $array3 = array( 2 => array( "score" => 79 ), 1 => array( "score" => 5 ), ); foreach( $array1 as $array1x ){ $key=key($array1x); if( in_array($key, $array2) ){ $this_score = $array1x[$key]['score']; $cum_score = isset($newarray[$key]['score']) ? $newarray[$key]['score'] : 0; $newarray[$key]['score'] = $cum_score + $this_score; } } print_r($newarray);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [2] => Array ( [score] => 79 ) [1] => Array ( [score] => 5 ) )

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:
49.47 ms | 401 KiB | 8 Q