LimitIterator::__construct
PHP function
Edit on GitHub ✎
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
Construct a LimitIterator
Description
LimitIterator::__construct(Iterator $iterator, int $offset = 0, int $limit = -1)
Constructs a new LimitIterator from an iterator with a given starting offset and maximum limit.
Parameters
iteratorThe
Iteratorto limit.offsetOptional offset of the limit.
limitOptional count of the limit.
Errors/Exceptions
Throws a ValueError if the offset is less than 0 or the limit is less than -1.
Changelog
| Version | Description |
|---|---|
| 8.0.0 | Now throws a ValueError if offset is less than 0; previously it threw a RuntimeException. |
| 8.0.0 | Now throws a ValueError if limit is less than -1; previously it threw a RuntimeException. |
Examples
LimitIterator::__construct() example
php
<?php
$ait = new ArrayIterator(array('a', 'b', 'c', 'd', 'e'));
$lit = new LimitIterator($ait, 1, 3);
foreach ($lit as $value) {
echo $value . "\n";
}
?>The above example will output:
output
b
c
d