PHP 7.1.2 Released

iterator_count

(PHP 5 >= 5.1.0)

iterator_countشمارش جز در تکرار شونده

Description

int iterator_count ( Traversable $iterator )

شمارش جز در تکرار شونده.

Parameters

iterator

تکرار شونده مشمول شمارش.

Return Values

تعداد اجزا در iterator.

Examples

Example #1 مثال iterator_count()

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

The above example will output:

int(4)

add a note add a note

User Contributed Notes 1 note

up
0
woody dot gilk at gmail dot com
5 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