What is the best way to reverse a custom collection created with new Varien_Data_Collection()
?
Is the collection already loaded? The class supports setOrder, so if you know how it's ordered and it isn't yet loaded yet, you can simply call setOrder on the same field, using Varien_Data_Collection::SORT_ORDER_DESC
or Varien_Data_Collection::SORT_ORDER_ASC
as appropriate. Alternatively if you only require the objects and nothing specific to the collection you could use.
// where $collection is your instance of Varien_Data_Collection
$reversedCollection = array_reverse($collection->toArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With