PHP Conference Japan 2024

CachingIterator::offsetGet

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

CachingIterator::offsetGetoffsetGet 的用途

說明

public CachingIterator::offsetGet(字串 $key): 混合
警告

此函式目前沒有說明文件;僅提供其參數列表。

參數

key

說明...

回傳值

說明...

新增筆記

使用者貢獻的筆記 1 則筆記

ddrake at dreamingmind dot com
4 年前
offsetGet($index) 會回傳儲存在快取中 $index 位置的值。在您迭代過這些項目之前,快取是空的,而且索引將不存在。
迭代

<?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 . '快取' . PHP_EOL;
var_export($cache->getCache());
echo
PHP_EOL;

echo
$cache->offsetGet('1') . PHP_EOL;
echo
$cache->offsetGet('2') . PHP_EOL;
?>

快取
array (
0 => 'a',
1 => 'b',
)

b
未定義的索引:2
To Top