问题
When I use sort($topics) I get something along the lines of:
- Apple
- Green
- Zebra
- grass
In this example, "grass" starts with a lower case g but ends up after "Zebra" which has a capital letter.
How do I make it so that it sorts it where it ignores whether the word starts with capitals or not?
- Apple
- Green
- grass
- Zebra
回答1:
Call usort() as usort($topics, 'strnatcasecmp').
strcasecmp would do the job, too, but strnatcasecmp will also sort properly when you have numbers in your string.
回答2:
There is natcasesort .
natcasesort($topics);
来源:https://stackoverflow.com/questions/7763936/sort-array-items-in-php-so-that-it-is-not-case-sensitive-to-letters