InfiniteIterator クラス
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
はじめに
InfiniteIterator は、 他のイテレータを受け取って無限に反復させます。 最後までたどり着いたときに手動で巻き戻す必要はありません。
クラス概要
/* メソッド */
/* 継承したメソッド */
}目次
- InfiniteIterator::__construct — InfiniteIterator を作成する
- InfiniteIterator::next — 内部イテレータを次に移動するか、巻き戻す
+add a note
User Contributed Notes 2 notes
Anonymous ¶
12 years ago
to loop through object keys and reset to the start, try this:
<?php
$obj = new stdClass();
$obj->Mon = "Monday";
$obj->Tue = "Tuesday";
$obj->Wed = "Wednesday";
$obj->Thu = "Thursday";
$obj->Fri = "Friday";
$obj->Sat = "Saturday";
$obj->Sun = "Sunday";
$infinate = new InfiniteIterator(new ArrayIterator($obj));
foreach ( new LimitIterator($infinate, 0, 14) as $value ) {
print($value . PHP_EOL);
}
?>
will output:
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Can be useful when doing date operations or recurring events
vascowhite at gmail dot com ¶
11 years ago
It is important to realise that rewind() must be called on any iterator before using it or you may experience undefined behaviour, see example code and output here http://3v4l.org/rvNpU
See this bug report https://bugs.php.net/bug.php?id=63823&edit=2 for a fuller explanation.
↑ and ↓ to navigate •
Enter to select •
Esc to close
Press Enter without
selection to search using Google