<?php
$data = [
[
'name' => 'Брянск'
],
[
'name' => 'Москва'
],
[
'name' => 'Бобруйск'
],
];
usort($data, function ($v1, $v2) {
return strcmp($v1['name'], $v2['name']);
});
$letter = null;
foreach ($data as $v) {
$currentLetter = mb_substr($v['name'], 0, 1, 'utf-8');
if ($currentLetter !== $letter) {
$letter = $currentLetter;
echo "--- $letter ---", PHP_EOL;
}
echo $v['name'], PHP_EOL;
}