当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP CachingIterator getInnerIterator()用法及代码示例


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

用法:

Iterator CachingIterator::getInnerIterator( void )

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


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

以下示例程序旨在说明PHP中的CachingIterator::getInnerIterator()函数:

示例1:

<?php 
     
// Declare an array 
$arr = array('G', 'e', 'e', 'k', 's'); 
     
// Create a new CachingIterator 
$cachIt = new CachingIterator( 
    new ArrayIterator($arr),  
    CachingIterator::FULL_CACHE 
); 
  
foreach($cachIt as $element) { 
      
    echo $element; 
      
    if($cachIt->hasNext()) { 
        echo ", "; 
    } 
} 
  
?>
输出:
G, e, e, k, s

示例2:

<?php 
     
// Declare an ArrayIterator 
$arr = array( 
    "a" => "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



相关用法


注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | CachingIterator getInnerIterator() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。