For Loops With Function Calls in the Test

For loops should not call functions inside the test for the loop when they can be computed beforehand.

Valid: A for loop that determines its end condition before the loop starts.

<em>$end = count($foo);</em> for ($i = 0; $i < $end; $i++) { echo $foo[$i]."\n"; }

Invalid: A for loop that unnecessarily computes the same value on every iteration.

for ($i = 0; $i < <em>count($foo)</em>; $i++) { echo $foo[$i]."\n"; }