note 124510 added to cachingiterator.offsetget

From: Date: Mon, 16 Dec 2019 03:06:52 +0000
Subject: note 124510 added to cachingiterator.offsetget
Groups: php.notes 
Request: Send a blank email to php-notes+get-213541@lists.php.net to get a copy of this message
offsetGet($index) returns the value stored at $index in the cache. Until you've iterated over the items, the cache is empty and the index will not exist. <?php $cache = new \CachingIterator( new \ArrayIterator(['a', 'b', 'c', 'd']), \CachingIterator::FULL_CACHE); $shortRange = range(0, 1); foreach ($shortRange as $index) { $cache->next(); } echo PHP_EOL . 'The cache' . PHP_EOL; var_export($cache->getCache()); echo PHP_EOL; echo $cache->offsetGet('1') . PHP_EOL; echo $cache->offsetGet('2') . PHP_EOL; ?> The cache array ( 0 => 'a', 1 => 'b', ) b Undefined index: 2 ---- 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.offsetget.php Edit -- https://master.php.net/note/edit/124510 Del: integrated -- https://master.php.net/note/delete/124510/integrated Del: useless -- https://master.php.net/note/delete/124510/useless Del: bad code -- https://master.php.net/note/delete/124510/bad+code Del: spam -- https://master.php.net/note/delete/124510/spam Del: non-english -- https://master.php.net/note/delete/124510/non-english Del: in docs -- https://master.php.net/note/delete/124510/in+docs Del: other reasons-- https://master.php.net/note/delete/124510 Reject -- https://master.php.net/note/reject/124510 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#213541) next »