iterator_count
Description
The iterator_count of SPL for PHP counts the elements in an iterator.
Syntax
iterator_count(
Traversable|array $iterator
): intParameters
iterator
The iterator being counted.
Return
Returns the number of elements in iterator.
Examples
1 · iterator
<?
$array =
[
"a" => "one",
"b" => "two",
"c" => "three"
];
$iterator = new ArrayIterator($array);
$return = iterator_count($iterator);
echo $return;
3
2 · position
<?
$array =
[
"a" => "one",
"b" => "two",
"c" => "three"
];
$iterator = new ArrayIterator($array);
var_dump($iterator->current());
iterator_count($iterator);
var_dump($iterator->current());
string(3) "one" NULL