(PHP 5 >= 5.1.0, PHP 7, PHP 8)
LimitIterator::__construct — 构造 LimitIterator
从具有给定起始offset和最大limit的iterator构造一个新的LimitIterator。
如果offset小于0或limit小于-1,则抛出ValueError。
| 版本 | 描述 |
|---|---|
| 8.0.0 | 如果offset小于0,现在会抛出ValueError;之前它会抛出RuntimeException。 |
| 8.0.0 | 如果limit小于-1,现在会抛出ValueError;之前它会抛出RuntimeException。 |
示例 #1 LimitIterator::__construct() 示例
<?php
$ait = new ArrayIterator(array('a', 'b', 'c', 'd', 'e'));
$lit = new LimitIterator($ait, 1, 3);
foreach ($lit as $value) {
echo $value . "\n";
}
?>以上示例将输出
b c d