CachingIterator::getCache()函数是PHP中的内置函数,用于检索缓存的内容。
用法:
array CachingIterator::getCache( void )
参数:该函数不接受任何参数。
返回值:该函数返回一个包含缓存项的数组。
以下示例程序旨在说明PHP中的CachingIterator::getCache()函数:
示例1:
// 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:
// 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"
}