PHP | CachingIterator getCache()函数
CachingIterator::getCache()函数是PHP中的一个内置函数,用于检索缓存的内容。
句法:
array CachingIterator::getCache( void )
参数:此函数不接受任何参数。
返回值:此函数返回一个包含缓存项的数组。
下面的程序说明了PHP中的 CachingIterator::getCache()函数:
方案一:
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"
}
方案二:
"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