3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['group' => 1, 'animal' => 'ape'], ['group' => 1, 'animal' => 'bat'], ['group' => 1, 'animal' => 'cat'], ['group' => 2, 'animal' => 'dog'], ['group' => 1, 'animal' => 'eel'], ['group' => 3, 'animal' => 'fox'], ['group' => 1, 'animal' => 'gnu'], ['group' => 2, 'animal' => 'hog'], ]; $result = []; foreach ($array as $row) { $result[$row['group']] ??= $row + ['count' => 0]; ++$result[$row['group']]['count']; } var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'group' => 1, 'animal' => 'ape', 'count' => 5, ), 1 => array ( 'group' => 2, 'animal' => 'dog', 'count' => 2, ), 2 => array ( 'group' => 3, 'animal' => 'fox', 'count' => 1, ), )

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:
104.66 ms | 406 KiB | 5 Q