As shown and tested on www.phpbench.com, calculating the size of your loop in advance can be a huge performance boost. Makes sense of course, still the nature of PHP could lead you to believe that there’s an optimization in place, even if there’s little sound logic supporting it.

1
2
3
4
// Faster
for ($i=0; $i < $size; $i++)
// Slower
for ($i=0; $i < sizeOf($x); $i++)
Count Benchmark

Count Benchmark