Re: DB_DataObject - using foreach instead of while

From: Date: Mon, 21 Aug 2006 18:44:16 +0000
Subject: Re: DB_DataObject - using foreach instead of while
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24931@lists.php.net to get a copy of this message
There IS a way to do this, if you are using PHP 5. You can subclass your data object and implement the ArrayIterator interface, or you can create a separate object for your result set and implement the interface there. Objects that have implemented this interface are iterable via a foreach loop. http://www.php.net/manual/en/language.oop5.iterations.php http://www.php.net/manual/en/ref.spl.php -- Nick On Aug 21, 2006, at 2:32 PM, Justin Patrin wrote:
On 8/21/06, Noel da Costa <noel.dacosta@magharl.co.uk> wrote:
Hi there, The syntax examples for DB_DataObject show how to use a while loop with ->fetch() to iterate over records. Is there a way of doing this using a foreach loop instead? I'm trying to optimize speed here.
How would foreach be better than while? foreach uses a copy of an array to loop over it. No, there is, of course, no way to do this as ->fetch() gets one record at a time. --Justin Patrin --PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.pear.general (#24931) next »