suche nach in der

iterator_to_array> <iterator_apply
Last updated: Fri, 18 May 2012

view this page in

iterator_count

(PHP 5 >= 5.1.0)

iterator_countCount the elements in an iterator

Beschreibung

int iterator_count ( Traversable $iterator )

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)



add a note add a note User Contributed Notes
iterator_count
Ard
31-Aug-2006 12:39
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_to_array> <iterator_apply
Last updated: Fri, 18 May 2012