PHP 7.1.2 Released

iterator_count

(PHP 5 >= 5.1.0)

iterator_countCount the elements in an iterator

Descrizione

int iterator_count ( Traversable $iterator )

Count the elements in an iterator.

Elenco dei parametri

iterator

The iterator being counted.

Valori restituiti

The number of elements in iterator.

Esempi

Example #1 iterator_count() example

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

Il precedente esempio visualizzerĂ :

int(4)

add a note add a note

User Contributed Notes 1 note

up
0
woody dot gilk at gmail dot com
3 days ago
When called, this function is effectively the same as:

<?php
$count
= 0;
$iterator->rewind();
while (
$iterator->valid()) {
   
$count++;
   
$iterator->next();
}
return
$count;
?>

If you ever need to create a mock of an iterator that is passed to iterator_count(), these are the methods to account for.
To Top