I'm sorry for the uncreative title.
I'm trying to group my array alphabetically. The accepted answer in this question (by Hugo Delsing) helped greatly to my task, but I still want to take things a bit further...
here's my current code:
$records = ['7th Trick', 'Jukebox', 'Dynamyte', '3rd Planet'];
$lastChar = '';
sort($records, SORT_STRING | SORT_FLAG_CASE);
foreach($records as $val) {
$char = strtolower($val[0]);
if ($char !== $lastChar) {
if ($lastChar !== '') echo "</ul>";
echo "<h2>".strtoupper($char)."</h2><ul>";
$lastChar = $char;
}
echo '<li>'.$val.'</li>';
}
echo "</ul>";
I want to make things so that non-alphabetic items would get grouped together instead of separated individually.
example:
"7th Trick" and "3rd Planet" get grouped together as non-alphabetic instead of displayed separately under "7" and "3" category respectively.
any idea how to do it?