note 124511 added to cachingiterator.offsetexists
| From: | ddrake at dreamingmind dot com | Date: | Mon, 16 Dec 2019 03:07:54 +0000 |
| Subject: | note 124511 added to cachingiterator.offsetexists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213542@lists.php.net to get a copy of this message | ||
offsetExists($index) examines the cache, not the inner or outer iterator.
<?php
$cache = new \CachingIterator(
new \ArrayIterator(['a', 'b', 'c', 'd']),
\CachingIterator::FULL_CACHE);
$shortRange = range(0, 1);
$fullRange = range(0, 3);
foreach ($shortRange as $index) {
$cache->next();
}
echo PHP_EOL . 'The cache' . PHP_EOL;
var_export($cache->getCache());
echo PHP_EOL;
foreach ($fullRange as $offset) {
print_r("cache offset '$offset' " .
($cache->offsetExists("$offset") == 1
? 'exists'
: "doesn't exist"
) . PHP_EOL);
}
?>
The cache
array (
0 => 'a',
1 => 'b',
)
cache offset '0' exists
cache offset '1' exists
cache offset '2' doesn't exist
cache offset '3' doesn't exist
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 2601:640:4080:5840:6c03:551a:f883:478e)
----
Manual Page -- http://php.net/manual/en/cachingiterator.offsetexists.php
Edit -- https://master.php.net/note/edit/124511
Del: integrated -- https://master.php.net/note/delete/124511/integrated
Del: useless -- https://master.php.net/note/delete/124511/useless
Del: bad code -- https://master.php.net/note/delete/124511/bad+code
Del: spam -- https://master.php.net/note/delete/124511/spam
Del: non-english -- https://master.php.net/note/delete/124511/non-english
Del: in docs -- https://master.php.net/note/delete/124511/in+docs
Del: other reasons-- https://master.php.net/note/delete/124511
Reject -- https://master.php.net/note/reject/124511
Search -- https://master.php.net/manage/user-notes.php