I want to remove last item from product collection

$collection = Mage::getModel('catalog/product')->getCollection();

But I have to avoid any 'loop' solutions.

2 Answers 2


Without context, I cannot say if this is a good idea, but if you have a loaded collection and want to remove the last item from the collection (not delete it), you can do this:

$lastId = $collection->getLastItem()->getId();

This works because internally the items are stored in an array with their id as key.


Additional database query but retaining collection:

$collection     = Mage::getModel('catalog/product')->getCollection();
$collectionSize = $collection->getSize();

Basic PHP but out of collection scope:

$collection = Mage::getModel('catalog/product')->getCollection();
$products   = $collection->getItems();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.