You can try
$group = array_reduce($data, function($a,$b) { $a[$b['surname']{0}][] = $b; return $a; } );
ksort($group);
foreach($group as $id => $data)
{
printf("<h4>%s</h4>\n",$id);
foreach($data as $name)
{
printf("%s %s\n",$name['name'],$name['surname']);
}
}
Output
<h4>B</h4>
Bill Buffalo
<h4>D</h4>
John Doe
Mark Doe
1
solved Output an array in alphabetical order [closed]