CKTIS / PHP
AppendIterator
Chain Iterator instances in append order without concatenating their arrays.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
new AppendIterator(); $chain->append($iterator);Chain Iterator instances in append order without concatenating their arrays. Each inner iterator keeps its keys, so two inputs can yield the same key. When materializing use fresh keys if both occurrences must survive. append requires an Iterator rather than a bare array.
$chain=new AppendIterator();
$chain->append(new ArrayIterator(["id"=>"A"]));
$chain->append(new ArrayIterator(["id"=>"B"]));
$pairs=[]; foreach($chain as $k=>$v){$pairs[]=[$k,$v];}
echo json_encode($pairs);
[["id","A"],["id","B"]]
Examples
<?php
$chain=new AppendIterator();
$chain->append(new ArrayIterator(["id"=>"A"]));
$chain->append(new ArrayIterator(["id"=>"B"]));
$pairs=[]; foreach($chain as $k=>$v){$pairs[]=[$k,$v];}
echo json_encode($pairs);
Result
[["id","A"],["id","B"]]