Note that you that the iterator parameter doesn't need to be of type Aggregate. As the spl documentation on http://www.php.net/~helly/php/ext/spl/ defines it in the following way:
iterator_count (Traversable $it).
So you can count the number of files in a given directory quite easily:
<?php iterator_count(new DirectoryIterator('path/to/dir/')); ?>
iterator_count
(PHP 5 >= 5.1.0)
iterator_count — Count the elements in an iterator
Parameter-Liste
-
iterator -
The iterator being counted.
Rückgabewerte
The number of elements in iterator.
Beispiele
Beispiel #1 iterator_count() example
<?php
$iterator = new ArrayIterator(array('recipe'=>'pancakes', 'egg', 'milk', 'flour'));
var_dump(iterator_count($iterator));
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
int(4)
iterator_count
Ard
31-Aug-2006 12:39
31-Aug-2006 12:39