note 28092 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Wed, 14 Nov 2012 22:35:57 +0000 |
| Subject: | note 28092 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191990@lists.php.net to get a copy of this message | ||
Note Submitter: ian at NO_SPAM dot verteron dot net
----
Note that foreach is faster than while! If you can replace the following:
<?php
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)...
<?php
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 :)