I am using this to sort according to last name: But – when in last name is accent, e.g. Šiko, Áron, etc, these names are at the end. How can I sort it properly? Answer Use multi-byte string functions. There is a function called strcoll which seems to suit your needs. More info: On how to sort an array of
Tag: sorting
Completely arbitrary sort order in MySQL with PHP
I have a table in MySQL that I’m accessing from PHP. For example, let’s have a table named THINGS: things.ID – int primary key things.name – varchar things.owner_ID – int for joining with another table My select statement to get what I need might look like: SELECT * FROM things WHERE owner_ID = 99; Pretty straightforward. Now, I’d like users
Preserve key order (stable sort) when sorting with PHP’s uasort
This question is actually inspired from another one here on SO and I wanted to expand it a bit. Having an associative array in PHP is it possible to sort its values, but where the values are equal to …
PHP Sort Array By SubArray Value
I have the following array structure: What is the best way to order the array in an incremental way, based on the optionNumber? So the results look like: Answer Use usort. In PHP ≥5.3, you should use an anonymous function instead: Note that both code above assume $a[‘optionNumber’] is an integer. Use @St. John Johnson’s solution if they are strings.
Sorting an array of arrays by the child array’s length?
What’s the best way in PHP to sort an array of arrays based on array length? e.g. Answer This will work: Note that this function will preserve the numerical keys. If you want to reset the keys, wrap it in a call to array_values().
glob() – sort array of files by last modified datetime stamp
I’m trying to display an array of files in order of date (last modified). I have done this buy looping through the array and sorting it into another array, but is there an easier (more efficient) way …