Re: Re: [PEPr] Comment on Networking::Monitor
| From: | Joshua Eichorn | Date: | Thu, 09 Dec 2004 19:23:28 +0000 |
| Subject: | Re: Re: [PEPr] Comment on Networking::Monitor | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34976@lists.php.net to get a copy of this message | ||
Bertrand Mansion wrote:
Joe Stump wrote:http://www.blueshoes.org/en/developer/php_bench/ -joshIt depends on the use. foreach() for small arrays is supposed to be faster than while(list() each()). Also, you don't have to reset() arrays after using foreach(), BUT foreach() makes a *copy* to work on, which can be resource heavy with really large arrays (ie. you'd have two copies of a 200k length array if you used foreach()). This is what I understand to be the differences. Things may have changed since I last looked into this. --Joe On Dec 9, 2004, at 10:04 AM, Robert Peake wrote:As said by Joe, speed is the difference. With PHP5, you can now use reference for values instead of copying (but this will probably make your code not PHP4 compatible) as in foreach ($arr as &$value) So if the size of the array is not too big, feel free to use foreach instead :) Bertrand I found the real home of that benchmark.Hi Bertrand, Yes -- I will double-check CS before moving to vote. s/if(/if (/g <- my best friend :) Why do you recommend foreach instead of while ... each?