표준 PHP 라이브러리(SPL) LimitIterator::__construct
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
LimitIterator::__construct — LimitIterator 생성
설명
public LimitIterator::__construct(Iterator $iterator
, int $offset
= 0, int $limit
= -1)
지정된 시작 offset
과 최대 limit
를 가진 Iterator
에서 새로운 LimitIterator를 생성합니다.
매개변수
iterator
- 제한할 Iterator입니다.
offset
- 제한의 선택적 오프셋입니다.
limit
- 제한의 선택적 개수입니다.
오류/예외
offset
이 0보다 작거나 limit
가 -1보다 작으면 ValueError를 발생시킵니다.
변경 로그
버전 | 설명 |
---|---|
8.0.0 | offset 이 0보다 작으면 이제 ValueError가 발생합니다. 이전에는 RuntimeException이 발생했습니다. |
8.0.0 | 이제 제한이 -1보다 작으면 ValueError가 발생합니다. 이전에는 RuntimeException이 발생했습니다. |
Examples
예제 #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