array of objects?
Posted: Tue Oct 11, 2005 12:30 am
I do not like using this kind of iteration of db results like this (news items in the db):
I would prefer putting all news items as objects in an array and then iterate over them like this:
For me this would be more convenient, as I may also need to do some tricks with the data in the news item object (for example, do some replacing or any other string manipulation).
Is it ok to use object arrays? What if I have 500 objects in the array? Can this method become a performance hit?
Code: Select all
while ($row = $rs->nextRow())
{
echo $row['headline'];
echo $row['body'];
}Code: Select all
foreach ($items as $item)
{
echo $item->getName();
echo $item->getBody();
}Is it ok to use object arrays? What if I have 500 objects in the array? Can this method become a performance hit?