3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $A = array( 'Z'=>array('d'=>array( 'v1'=>10, 'v2'=>20, 'v3'=>30 ) ), 'A'=>array('a'=>array( 'v1'=>1, 'v2'=>2, 'v3'=>3 ), 'b'=>array( 'v1'=>1, 'v2'=>2, 'v3'=>3 ) ), 'B'=>array('a'=>array( 'v1'=>1, 'v2'=>2, 'v3'=>3 ), 'b'=>array( 'v1'=>1, 'v2'=>2, 'v3'=>3 ) ), 'C'=>array('a'=>array( 'v1'=>9, 'v2'=>8, 'v3'=>7 ), 'b'=>array( 'v1'=>6, 'v2'=>5, 'v3'=>4 ) ) ); $total=array_reduce($A,function(&$r,$v){ array_walk($v,function($val,$key)use(&$r){ if(!isset($r[$key])) $r[$key]=array(); array_walk($val,function($vv,$vk)use(&$r,$key){ if(!isset($r[$key][$vk])) $r[$key][$vk]=0; $r[$key][$vk]+=$vv; }); }); return $r; },array()); print_r($total);
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [d] => Array ( [v1] => 10 [v2] => 20 [v3] => 30 ) [a] => Array ( [v1] => 11 [v2] => 12 [v3] => 13 ) [b] => Array ( [v1] => 8 [v2] => 9 [v3] => 10 ) )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/8vZp4 on line 47
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/8vZp4 on line 47
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/8vZp4 on line 47
Process exited with code 255.