I have a page with a SELECT tag proposing to choose between multiple countries.
The SELECT options are dynamically generated, a SQL query select all the countries from the database, not sorted, and add them into an array.
Then, I use asort to sort the array and propose the SELECT.
It works as long as there isn't accented characters, and accented character options are sorted after everything.
Check it on the page : http://worldisbeautiful.net/partager/?force_language=fr
- make sure force_language=fr is on, otherwise it will be english by default
- check the source code, you'll see 3 commented tests I made with the results
I tried, with no luck, solutions proposed on these questions :
- Sort an array with special characters in PHP
- Sorting array with collation
- How to sort an array considering localization?
For information, i receive sorted country data from databases but in english, then i localize them in french and due to complete name change it's unsorted (ie in french, united stats is états-unis).