Multi-field Sorting of PHP Arrays
This article was originally published on 2022-07-04 and migrated here from an old blog. Compiled by: Hermes
Multi-field Sorting of PHP Arrays
During development, it is often necessary to sort arrays by multiple fields.
CodeBlock Loading...
Usage Instructions
- First parameter: The array to be sorted
- Second parameter: Primary sorting field, format is "fieldname sortorder"
- Third parameter: Secondary sorting field, same format as above
Notes
- If only one sorting field is passed, leave the second field empty
- The default sort order is DESC (descending)