PHP will do the counting every time the loop repeats. However, PHP maintains an internal track of the size of the array, so counting is a relatively cheap operation. This is not as if PHP literally counted every element in the array. But he is still not free.
Using a very simple 10 mm element array that performs a simple variable increment, I get 2.5 seconds for the loop version in the loop and 0.9 seconds for the count-before-loop loop. Quite a big difference, but not "massive".
edit: code:
$x = range(1, 10000000); $z = 0; $start = microtime(true); for ($i = 0; $i < count($x); $i++) { $z++; } $end = microtime(true); // $end - $start = 2.5047581195831
Switch to do
$count = count($x); for ($i = 0; $i < $count; $i++) {
and otherwise everything else is the same, time is 0.96466398239136
source share