PHP | CachingIterator getCache() Function
Last Updated :
20 Nov, 2019
The CachingIterator::getCache() function is an inbuilt function in PHP which is used to retrieve the contents of the cache.
Syntax:
array CachingIterator::getCache( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns an array containing the cache items.
Below programs illustrate the CachingIterator::getCache() function in PHP:
Program 1:
<?php
$arr = array ( 'G' , 'e' , 'e' , 'k' , 's' );
$cachIt = new CachingIterator(
new ArrayIterator( $arr ),
CachingIterator::FULL_CACHE
);
$cachIt ->next();
var_dump( $cachIt ->getCache());
$cachIt ->next();
var_dump( $cachIt ->getCache());
?>
|
Output:
array(1) {
[0]=>
string(1) "G"
}
array(2) {
[0]=>
string(1) "G"
[1]=>
string(1) "e"
}
Program 2:
<?php
$arr = array (
"a" => "Geeks" ,
"b" => "for" ,
"c" => "Geeks" ,
"d" => "Computer" ,
"e" => "Science" ,
"f" => "Portal"
);
$cachIt = new CachingIterator(
new ArrayIterator( $arr ),
CachingIterator::FULL_CACHE
);
$cachIt ->next();
$cachIt ->next();
$cachIt ->next();
var_dump( $cachIt ->getCache());
$cachIt ->next();
var_dump( $cachIt ->getCache());
?>
|
Output:
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"
}
Reference: https://www.php.net/manual/en/cachingiterator.getcache.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...