Does count() really count the all the elements of a PHP array, or is this value cached somewhere and just gets retrieved?
In PHP 5+ the length is stored in the array so the counting is not done each time.
EDIT: You also might find this analysis interesting: PHP Count Performance. Although the length of the array is maintained by the array, it still seems as though it is faster to hold on to it if you are going to call count() many times.