CKTIS / PHP
ArrayIterator
Enveloppe un tableau dans un objet modifiable par indice, dénombrable et muni d’un curseur. seek prend la position de parcours depuis zéro, même pour une table associative, et lève OutOfBoundsException hors limites. getArrayCopy renvoie le contenu courant en tableau.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
new ArrayIterator($values)Enveloppe un tableau dans un objet modifiable par indice, dénombrable et muni d’un curseur. seek prend la position de parcours depuis zéro, même pour une table associative, et lève OutOfBoundsException hors limites. getArrayCopy renvoie le contenu courant en tableau.
$it=new ArrayIterator(["a"=>4,"z"=>6]); $it["z"]=7; $it->seek(1);
$result=[$it->key(),$it->current(),count($it),$it->getArrayCopy()];
try{$it->seek(9);}catch(OutOfBoundsException $e){$result[]=get_class($e);}
echo json_encode($result);
["z",7,2,{"a":4,"z":7},"OutOfBoundsException"]
Exemples
<?php
$it=new ArrayIterator(["a"=>4,"z"=>6]); $it["z"]=7; $it->seek(1);
$result=[$it->key(),$it->current(),count($it),$it->getArrayCopy()];
try{$it->seek(9);}catch(OutOfBoundsException $e){$result[]=get_class($e);}
echo json_encode($result);
Résultat
["z",7,2,{"a":4,"z":7},"OutOfBoundsException"]