iterator_count

(PHP 5 >= 5.1.0, PHP 7)

iterator_countCount the elements in an iterator

Açıklama

iterator_count ( Traversable $iterator ) : int

Count the elements in an iterator. iterator_count() is not guaranteed to retain the current position of the iterator.

Değiştirgeler

iterator

The iterator being counted.

Dönen Değerler

The number of elements in iterator.

Örnekler

Örnek 1 iterator_count() example

<?php
$iterator 
= new ArrayIterator(array('recipe'=>'pancakes''egg''milk''flour'));
var_dump(iterator_count($iterator));
?>

Yukarıdaki örneğin çıktısı:

int(4)

Örnek 2 iterator_count() modifies position

<?php
$iterator 
= new ArrayIterator(['one''two''three']);
var_dump($iterator->current());
var_dump(iterator_count($iterator));
var_dump($iterator->current());
?>

Yukarıdaki örneğin çıktısı:

string(3) "one"
int(3)
NULL

Örnek 3 iterator_count() in foreach loops

<?php
$iterator 
= new ArrayIterator(['one''two''three']);
foreach (
$iterator as $key => $value) {
    echo 
"$key$value ("iterator_count($iterator), ")\n";
}
?>

Yukarıdaki örneğin çıktısı:

0: one (3)