3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function addArrays(array $array, array $array = null) { $results = []; foreach (func_get_args() as $array) { $campaign = $array['campaign']; if (isset($results[$campaign])) { $results[$campaign]['am']['agent_count'] += $array['am']['agent_count']; // ... } else { $results[$campaign] = $array; } } return $results; } $array1 = [ 'campaign' => 'foo', 'am' => [ 'agent_count' => 17, ], ]; $array2 = [ 'campaign' => 'bar', 'am' => [ 'agent_count' => 65, ], ]; $array3 = [ 'campaign' => 'foo', 'am' => [ 'agent_count' => 78, ], ]; var_dump(addArrays($array1, $array2, $array3));
Output for 5.4.0 - 5.6.28
array(2) { ["foo"]=> array(2) { ["campaign"]=> string(3) "foo" ["am"]=> array(1) { ["agent_count"]=> int(95) } } ["bar"]=> array(2) { ["campaign"]=> string(3) "bar" ["am"]=> array(1) { ["agent_count"]=> int(65) } } }
Output for 5.1.0 - 5.3.25
Parse error: syntax error, unexpected '[' in /in/CpSEq on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/CpSEq on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/CpSEq on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/CpSEq on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/CpSEq on line 3
Process exited with code 255.