I have an array containing arrays of names and other details, in alphabetical order. Each array includes the first letter associated with the name.
Array (
Since your array is already sorted, you could just loop through and track the last letter shown. When it changes, you know you're on the next letter.
$lastChar = ''; foreach($singers as $s) { if ($s[0] != $lastChar) echo "\n".$s[0]."\n - \n"; echo $s[1]."\n"; $lastChar = $s[0]; }