I have an array that already contains all it’s values in alphabetical order:
Alligator
Alpha
Bear
Bees
Banana
Cat
Cougar
Now I just want to list the first letter each starts with above it like so:
A
---
Alligator
Alpha
B
---
Bear
Bees
Banana
C
---
Cat
Cougar
etc...
How can this be done?
The solution is to keep in a variable the first letter of the previously printed word, like:
NB: if some entries start with a lower-case letter and others with upper-case letters, use the
strcasecmpfunction in the test instead of!==.