note 48214 added to control-structures.foreach
| From: | caliban at darklock dot com | Date: | Wed, 15 Dec 2004 15:48:06 +0000 |
| Subject: | note 48214 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81822@lists.php.net to get a copy of this message | ||
Many old code examples dating back to PHP3 use this construct:
while(list($x,$y)=each($a)) {...}
However, on PHP4 and PHP5, you have this construct:
foreach($a as $x=>$y) {...}
The latter construct is almost twice as fast as the former, with the usual caveats about
architecture and compiler and whatnot having an effect.
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48214
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48214&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48214&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48214&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48214&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48214&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48214&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48214&report=yes
Search -- http://master.php.net/manage/user-notes.php