📜  PHP | CachingIterator getInnerIterator()函数

📅  最后修改于: 2022-05-13 01:56:55.274000             🧑  作者: Mango

PHP | CachingIterator getInnerIterator()函数

CachingIterator::getInnerIterator()函数是PHP中的一个内置函数,用于返回发送给构造函数的迭代器。

句法:

Iterator CachingIterator::getInnerIterator( void )

参数:此函数不接受任何参数。

返回值:此函数返回一个实现 Iterator 接口的对象。

下面的程序说明了PHP中的 CachingIterator::getInnerIterator()函数:

方案一:

hasNext()) {
        echo ", ";
    }
}
  
?>
输出:
G, e, e, k, s

方案二:

 "Geeks",
    "b" => "for",
    "c" => "Geeks",
    "d" => "Computer",
    "e" => "Science",
    "f" => "Portal"
);
   
// Create a new CachingIterator
$cachIt = new CachingIterator(
    new ArrayIterator($arr), 
    CachingIterator::FULL_CACHE
);
  
foreach($cachIt as $key => $value) {
      
    echo $key . " => " . $value;
      
    if($cachIt->hasNext()) {
        echo "\n";
    }
}
  
?>
输出:
a => Geeks
b => for
c => Geeks
d => Computer
e => Science
f => Portal

参考: https://www. PHP.net/manual/en/cachingiterator.getinneriterator。 PHP