XF 2.0 Best way to sort ArrayCollection (from Finder) by column after fetch()?

Hello!

I have a finder query, which fetches some entities from the database.
I want to sort the returned ArrayCollection by some column after a few operations on the initial collection.
How should I do that best in the code?
I mean that in the initial fetch I sort by column A.
Then later, I want to sort by column B and then loop thorugh the collection again.

Thanks in advance,
Tommi
 
There's not really any good sorting methods available on collections, unfortunately. You have to use arrays as an intermediate:

PHP:
$entities = $entities->toArray();
$entities = \XF\Util\Arr::columnSort($entities, 'column');
$entities = \XF::em()->getBasicCollection($entities);
 
Back
Top Bottom