I want to loop over an array of product IDs in Magento. In the loop I am displaying some custom attributes of the products as:
foreach ($products as $product
First of all I would like to explain the difference between Mage::getSingleton() and Mage::getModel() functions.
When you call the function Mage::getSingleton('catalog/product') magento will search in the memory whether there is any object available. If not it will create a new object for Mage_catalog_Model_product class. In the first iteration of the foreach loop this happens. But from the second iteration when magento searches in memory for Mage_catalog_Model_product class object it will find the object which was called in the first iteration. So magento won't create any new object and instead it will call the same object which is already in the memory.
BUT,
If you use Mage::getModel('catalog/product) this function always creates new object of Mage_catalog_Model_product class in the memory whenever you called it. So in the loop this function will create one object per iteration.