3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = [ ['a' => 1, 'b' => 2], ['a' => 2, 'b' => 2] ]; $data = new stdClass(); $data->count = 0; $data->a = 0; $data->b = 0; $cb = function($value, $key, &$data) { $data->count = $data->count + 1; $data->a = $data->a + $value['a']; $data->b = $data->b + $value['b']; }; array_walk($array, $cb, $data); var_dump($data);
based on e0Iu8
Output for 5.4.0 - 7.2.6
object(stdClass)#1 (3) { ["count"]=> int(2) ["a"]=> int(3) ["b"]=> int(4) }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/pYepQ on line 3
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 '[' in /in/pYepQ on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/pYepQ on line 3
Process exited with code 255.