Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

MultipleIterator

Advance several iterators together in rows.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

new MultipleIterator($flags)

Advance several iterators together in rows. MIT_NEED_ALL stops at the shortest input, whereas MIT_NEED_ANY continues with null for exhausted inputs. MIT_KEYS_ASSOC uses the distinct labels supplied to attachIterator for the row fields. A null field may also be a genuine source value.

function rows(int $mode): array { $m=new MultipleIterator($mode|MultipleIterator::MIT_KEYS_ASSOC); $m->attachIterator(new ArrayIterator([1,2]),"n"); $m->attachIterator(new ArrayIterator(["A"]),"tag"); return iterator_to_array($m,false); }
echo json_encode([rows(MultipleIterator::MIT_NEED_ALL),rows(MultipleIterator::MIT_NEED_ANY)]);
[[{"n":1,"tag":"A"}],[{"n":1,"tag":"A"},{"n":2,"tag":null}]]

Examples

<?php
function rows(int $mode): array { $m=new MultipleIterator($mode|MultipleIterator::MIT_KEYS_ASSOC); $m->attachIterator(new ArrayIterator([1,2]),"n"); $m->attachIterator(new ArrayIterator(["A"]),"tag"); return iterator_to_array($m,false); }
echo json_encode([rows(MultipleIterator::MIT_NEED_ALL),rows(MultipleIterator::MIT_NEED_ANY)]);

Result

[[{"n":1,"tag":"A"}],[{"n":1,"tag":"A"},{"n":2,"tag":null}]]

Sources