CKTIS / PHP
CachingIterator
Ajoute une anticipation d’un élément. hasNext indique si un élément suit le courant, utile pour placer un séparateur.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
new CachingIterator($iterator, CachingIterator::FULL_CACHE)Ajoute une anticipation d’un élément. hasNext indique si un élément suit le courant, utile pour placer un séparateur. FULL_CACHE mémorise les paires visitées pour getCache, consomme de la mémoire et écrase une ancienne valeur de même clé.
$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}]
Exemples
<?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()]);
Résultat
[[["a",true],["b",false]],{"a":2,"b":3}]