Syntax:void CachingIterator::next (void)
Parameters:This function takes no parameters.
Returned value:This function does not return any value.The following programs illustrate the CachingIterator function::next() in PHP:
Program 1:
// Declare the 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
$cachIt
-> current().
""
;
$cachIt
-> next();
}
?>
Exit:G es
Program 2:
// Declare 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
.
"= >"
.
$cachIt
-> current().
""
;
$cachIt
-> next();
}
?>
Exit:a = > Geeks c = > Geeks e = > Science
Link: https://www.php.net /manual/en/cachingiterator.next.php