CachingIterator::offsetSet

(PHP 5 >= 5.2.0, PHP 7)

CachingIterator::offsetSetThe offsetSet purpose

설명

public void CachingIterator::offsetSet ( string $index , string $newval )
Warning

이 함수는 현재 문서화 되어있지 않습니다; 인수 목록만을 제공합니다.

인수

index

The index of the element to be set.

newval

The new value for the index.

반환값

값을 반환하지 않습니다.

add a note add a note

User Contributed Notes 1 note

up
0
ddrake at dreamingmind dot com
4 years ago
offsetSet($index, $newval) will change an existing cache value or create a new cache entry

<?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->offsetSet('0', 'manual change') . PHP_EOL;
        echo
$cache->offsetSet('3', 'manual entry') . PHP_EOL;
?>

The cache
array (
  0 => 'a',
  1 => 'b',
)

The cache
array (
  0 => 'manual change',
  1 => 'b',
  3 => 'manual entry',
)

There is no requirement that the offset exist in the inner iterator, or that the offset exists in the cache.

<?php
        $cache
= new \CachingIterator(
            new \
ArrayIterator([]),
            \
CachingIterator::FULL_CACHE);

        echo
$cache->offsetSet('22', 'manual entry') . PHP_EOL;

        echo
PHP_EOL . 'The cache' . PHP_EOL;
       
var_export($cache->getCache());
        echo
PHP_EOL;

       
print_r("cache offset '22' " .
            (
$cache->offsetExists('22') == 1
               
? 'exists'
               
: "doesn't exist"
           
) . PHP_EOL);
?>

The cache
array (
  22 => 'manual entry',
)
cache offset '22' exists
To Top