I'm working on a function to do multi-leveled sorting (sort within a sort, for a lack of better term) for a client. Say we have a list of objects with different attributes such as:
- name - object's name
- type - object type
- date - some date attribute
Let's say I wanted to sort the list first chronologically, then by object type, then alphabetically. How would I go about doing that?
currently I am using usort() to pass in my own comparing function, which will convert the above attributes to integers with different weight; eg. If the primary sorting is by date, I convert it to some integer, multiply it by 1000, convert the next tier of sorting to an integer (in this case the type), multiply it by 100, and so on, then add it all together to determine whether an object is < or > another.
Is there a much simpler/elegant solution? Thanks
EDIT: to clarify, is there a better way to do multi-level sorting without converting everything to a 'weight'?