[TYPO3-dev] FYI: comparing execution speed of some php functions

Ernesto Baschny [cron IT] ernst at cron-it.de
Mon Jun 29 12:05:51 CEST 2009


Jigal van Hemert wrote: on 27.06.2009 10:55:

> My conclusion:
> Contrary to what we were taught in the era of PHP4 the foreach() loop
> doesn't take up more memory than the while() loop. Foreach is way faster
> than while and if you need to change the elements of the array use
> foreach with references to the value(s).

If you do that (reference to value), don't forget to unset the $value at
the end of your foreach loop, else you can get pretty strange
side-effects with the original array:

foreach ($arr as &$value) {
   ...
   unset($value);
}

I will post a RFC fixing that in one TYPO3 core function soon.

Cheers,
Ernesto




More information about the TYPO3-dev mailing list