NogDog;10912368 wrote:It always makes my head hurt when I try to read it, so I just stick with the usort(). 😉
I can now usually get my queries to give me the data already sorted as needed.
array_multisort's argument list is structured the same way as SQL's ORDER BY clause. Once that bit makes sense the rest follows. The hassle is that you have to construct the sort keys manually (ref. Installer's example) - several potentially large temp variables.
I still much prefer usort. That said, precomputing keys can make sense if it takes a lot of work to derive them (usort doesn't retain that from one call to the next, so every comparison requires the whole lot to be redone).
That said, you can then use those precomputed keys in usort.
That said, doing so requires a bit of massaging to get the array into and out of the form usort requires.
That said, sometimes there is no clear-cut "key" that can be derived for each element independently of all the others and then array_multisort simply can't be used.