update : 2015.11.03
php.shukuma.com

검색:
 
 
Count the elements in an iterator

iterator_count

(PHP 5 >= 5.1.0)

iterator_countCount the elements in an iterator

설명

int iterator_count ( Traversable $iterator )

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

인수

iterator

The iterator being counted.

반환값

The number of elements in iterator.

예제

Example #1 iterator_count() example

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

위 예제의 출력:

int(4)

Example #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());
?>

위 예제의 출력:

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

Example #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";
}
?>

위 예제의 출력:

0: one (3)