CachingIterator::getCache()函数是PHP中的内置函数,用于检索缓存的内容。
用法:
array CachingIterator::getCache( void )
参数:该函数不接受任何参数。
返回值:该函数返回一个包含缓存项的数组。
以下示例程序旨在说明PHP中的CachingIterator::getCache()函数:
示例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
);
// Move to next position
$cachIt->next();
// Display the content of cache
var_dump($cachIt->getCache());
// Move to next position
$cachIt->next();
// Display the content of cache
var_dump($cachIt->getCache());
?>
输出:
array(1) { [0]=> string(1) "G" } array(2) { [0]=> string(1) "G" [1]=> string(1) "e" }
示例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
);
// Move to next position
$cachIt->next();
$cachIt->next();
$cachIt->next();
// Display the content of cache
var_dump($cachIt->getCache());
// Move to next position
$cachIt->next();
// Display the content of cache
var_dump($cachIt->getCache());
?>
输出:
array(3) { ["a"]=> string(5) "Geeks" ["b"]=> string(3) "for" ["c"]=> string(5) "Geeks" } array(4) { ["a"]=> string(5) "Geeks" ["b"]=> string(3) "for" ["c"]=> string(5) "Geeks" ["d"]=> string(8) "Computer" }
参考: https://www.php.net/manual/en/cachingiterator.getcache.php
相关用法
- PHP CachingIterator next()用法及代码示例
- PHP CachingIterator key()用法及代码示例
- PHP CachingIterator getFlags()用法及代码示例
- PHP CachingIterator rewind()用法及代码示例
- PHP CachingIterator current()用法及代码示例
- PHP CachingIterator __construct()用法及代码示例
- PHP CachingIterator getInnerIterator()用法及代码示例
- PHP CachingIterator setFlags()用法及代码示例
- PHP pos()用法及代码示例
- PHP end()用法及代码示例
- p5.js cos()用法及代码示例
- d3.js d3.lab()用法及代码示例
注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | CachingIterator getCache() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。