3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $their_dishes = array( array("name"=> "Vindaloo", "quantity"=> 1, "total"=> "5.80" ), array( "name"=> "Vindaloo", "quantity"=> 2, "total"=> "10.80", ), array( "name"=> "eggs and beans", "quantity"=> 21, "total"=> "100.90", ), array( "name"=> "eggs and beans", "quantity"=> 2, "total"=> "3.90", ) ); $my_dishes = []; foreach($their_dishes as $dish) { if(!isset($my_dishes[$dish->name])) { $my_dishes[$dish->name] = 1; } else { $my_dishes[$dish->name]++; } } foreach($my_dishes as $name => $count) { printf("%s: %d\n", $name, $count); }
based on GGUaT
Output for 7.2.0 - 7.3.0beta1
Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 27 Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 29 Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 27 Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 33 Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 27 Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 33 Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 27 Notice: Trying to get property 'name' of non-object in /in/jJBvK on line 33 : 4
Output for 5.4.0 - 7.1.20
Notice: Trying to get property of non-object in /in/jJBvK on line 27 Notice: Trying to get property of non-object in /in/jJBvK on line 29 Notice: Trying to get property of non-object in /in/jJBvK on line 27 Notice: Trying to get property of non-object in /in/jJBvK on line 33 Notice: Trying to get property of non-object in /in/jJBvK on line 27 Notice: Trying to get property of non-object in /in/jJBvK on line 33 Notice: Trying to get property of non-object in /in/jJBvK on line 27 Notice: Trying to get property of non-object in /in/jJBvK on line 33 : 4
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/jJBvK on line 23
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/jJBvK on line 23
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/jJBvK on line 23
Process exited with code 255.