ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
CachingIterator此对象支持在另一个迭代器上缓存迭代 ``` CachingIterator extends IteratorIterator implements OuterIterator , ArrayAccess , Countable { /* 常量 */ const integer CALL_TOSTRING = 1 ;//将每个元素转换为字符串。 const integer CATCH_GET_CHILD = 16 ;//在访问儿童时不要抛出异常 const integer TOSTRING_USE_KEY = 2 ;//使用键将其转换为字符串 const integer TOSTRING_USE_CURRENT = 4 ;//使用current转换为string const integer TOSTRING_USE_INNER = 8 ;//使用inner 转换为字符串 const integer FULL_CACHE = 256 ;//缓存所有读取的数据 /* 方法 */ public getCache ( void ) : array -- 检索缓存的内容 public getFlags ( void ) : int -- 获取使用的标志 public hasNext ( void ) : void -- 检查内部迭代器是否具有有效的下一个元素 public setFlags ( int $flags ) : void -- 设置表标志 public __toString ( void ) : void //IteratorIterator public __construct ( Iterator $iterator [, int $flags = self::CALL_TOSTRING ] ) //OuterIterator public getInnerIterator ( void ) : Iterator public current ( void ) : mixed public key ( void ) : scalar public next ( void ) : void public rewind ( void ) : void public valid ( void ) : void //Countable public count ( void ) : int //ArrayAccess public offsetExists ( mixed $index ) : void public offsetGet ( string $index ) : void public offsetSet ( mixed $index , mixed $newval ) : void public offsetUnset ( string $index ) : void } ``` ``` //该代码段将打印出所有缓存的元素(foreach). $cache = new CachingIterator(new ArrayIterator(range(1,100)), CachingIterator::FULL_CACHE); foreach ($cache as $c) { } print_r($cache->getCache());//[0=>1,1=>2,...,99=>100] ```