note 102866 deleted from class.domnodelist by danbrown

From: Date: Fri, 11 Mar 2011 14:50:16 +0000
Subject: note 102866 deleted from class.domnodelist by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177797@lists.php.net to get a copy of this message
Note Submitter: vector dot kerr at gmail dot com ---- You may also iterate over a DOMNodeList which is useful if you don't like creating extra variables. <?PHP foreach( $nodelist as $index => $node ) { /* ... */ } ?> @geompse: The reason that this ... <?PHP for( $pos=0; $pos<$nodelist->length; $pos++ ) { /* ... */ } ?> ... takes so long is because each time the loop progresses and the conditions are checked, the length of the node list must be recalculated. Your alternative... <?PHP $length = $nodelist->length; for( $i = 0; $i < $length; $i++ ) { /* ... */ } ?> ... stores the value once, which is a more appropriate approach.

« previous php.notes (#177797) next »