Magento is the best way to reverse the collection

What is the best way to modify a custom collection created with new Varien_Data_Collection()?

+5
source share
1 answer

Is the collection already uploaded? The class supports setOrder, so if you know how it is ordered and not yet loaded, you can simply call setOrder in the same field using Varien_Data_Collection::SORT_ORDER_DESCor Varien_Data_Collection::SORT_ORDER_ASC. Alternatively, if you only need objects and nothing special for a collection that you could use.

// where $collection is your instance of Varien_Data_Collection
$reversedCollection = array_reverse($collection->toArray());
+6
source

All Articles