3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array("bla","ble","blu","ab","bc","asdda","fju","ha","y","yi","yid"); $sorted_array = $array; natsort($sorted_array); $grouped_array = array(); foreach ($sorted_array as $item) { $letter = substr($item, 0, 1); $grouped_array[$letter][] = $item; } var_dump($grouped_array);
based on bWIET
Output for 4.3.0 - 7.1.0
array(5) { ["a"]=> array(2) { [0]=> string(2) "ab" [1]=> string(5) "asdda" } ["b"]=> array(4) { [0]=> string(2) "bc" [1]=> string(3) "bla" [2]=> string(3) "ble" [3]=> string(3) "blu" } ["f"]=> array(1) { [0]=> string(3) "fju" } ["h"]=> array(1) { [0]=> string(2) "ha" } ["y"]=> array(3) { [0]=> string(1) "y" [1]=> string(2) "yi" [2]=> string(3) "yid" } }