Is it possible to output the results of an array into an HTML list sorted in alphabetical order. Here’s what I mean. I have an array in the following format:
$myArray = array(
"apple" => "Fruit that grows ...",
"car" => "Vehicle on four...",
"ant" => "Insect ..."
...
);
Desired output:
<ul>A
<li>ant</li>
<li>apple</li>
</ul>
<ul>C
<li>car</li>
</ul>
etc.
First, sort the array alphabetically by key:
Or if you want to do a case-insensitive sort:
Then create a temporary array to group all words starting with the same letter into sub-arrays:
Finally, render the HTML: