3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $phrases = array("Aaa", "abb", "acc", "bbb", "bb2"); $groups = array(); foreach($phrases as $phrase) { $firstLetter = mb_strtoupper($phrase{0}); $groups[$firstLetter][] = $phrase; } print_r($groups);
Output for 4.3.0 - 7.1.0
Array ( [A] => Array ( [0] => Aaa [1] => abb [2] => acc ) [B] => Array ( [0] => bbb [1] => bb2 ) )