1
我目前正在編寫一個類來實現SeekableIterator接口並且遇到問題。我有兩個我正在使用的內部數組,並且希望允許從類外部對它們進行迭代。沒有首先在類中合併兩個數組,有沒有簡單的方法呢?這裏是什麼,我試圖做一個簡單的例子:PHP:實現SeekableIterator接口
class BookShelf implements ArrayAccess, Countable, SeekableIterator {
protected $_books = array(...);
protected $_magazines = array(...);
/**** CLASS CONTENT HERE ****/
}
$shelf = new BookShelf();
// Loops through both arrays, first books (if any) and then magazines (if any)
foreach($shelf as $item) {
echo $item;
}