CKTIS / PHP
CachingIterator
Acrescenta antecipação de um elemento. hasNext indica se existe outro após o atual, útil para separadores.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
new CachingIterator($iterator, CachingIterator::FULL_CACHE)Acrescenta antecipação de um elemento. hasNext indica se existe outro após o atual, útil para separadores. FULL_CACHE guarda os pares visitados para getCache, usa memória e substitui entradas com a mesma chave.
$it=new CachingIterator(new ArrayIterator(["a"=>2,"b"=>3]),CachingIterator::FULL_CACHE);
$look=[]; foreach($it as $k=>$v){$look[]=[$k,$it->hasNext()];}
echo json_encode([$look,$it->getCache()]);
[[["a",true],["b",false]],{"a":2,"b":3}]
Exemplos
<?php
$it=new CachingIterator(new ArrayIterator(["a"=>2,"b"=>3]),CachingIterator::FULL_CACHE);
$look=[]; foreach($it as $k=>$v){$look[]=[$k,$it->hasNext()];}
echo json_encode([$look,$it->getCache()]);
Resultado
[[["a",true],["b",false]],{"a":2,"b":3}]