note 28092 added to control-structures.foreach
| From: | ian at NO_SPAM dot verteron dot net | Date: | Wed, 01 Jan 2003 21:29:42 +0000 |
| Subject: | note 28092 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41553@lists.php.net to get a copy of this message | ||
Note that foreach is faster than while! If you can replace the following:
reset($array);
while(list($key, $val) = each($array))
{
$array[$key] = $val + 1;
}
...with this (although there are functional differences, but for many purposes this replacement will
behave the same way)...
foreach($array as $key => $val)
{
$array[$key] = $val + 1;
}
You will notice about 30% - 40% speed increase over many iterations. Might be important for those
ultra-tight loops :)
--
http://www.php.net/manual/en/control-structures.foreach.php
http://master.php.net/manage/user-notes.php?action=edit+28092
http://master.php.net/manage/user-notes.php?action=delete+28092
http://master.php.net/manage/user-notes.php?action=reject+28092