I need help for my absolute-noob question about array sorting. I'm using a function I found here: Group array results in Alphabetic order PHP to sort array values alphabetically.
$records = ['Aaaaa', 'Aaaa2', 'bbb', 'bbb2', 'Dddd'];
$lastChar = '';
sort($records, SORT_STRING | SORT_FLAG_CASE);
foreach($records as $val) {
$char = $val[0]; //first char
if ($char !== $lastChar) {
if ($lastChar !== '')
echo '<br>';
echo strtoupper($char).'<br>'; //print A / B / C etc
$lastChar = $char;
}
echo $val.'<br>';
}
?>
[ EDIT ] What i would like to do is to export each alphabetic group of array values into files, without even echoing, that would go:
foreach(){
$group = ??; //group values alphabetically into a variable
export($group); //input the variable into my exporting function.
}
So that the end result is I would have separate files (ie: a.txt, b.txt -- z.txt). I think this can be done with the function above, I just don't know where to put the exporting function.
Hope I'm not too confusing.