CKTIS / PHP
FilterIterator
Subclass this abstract wrapper and implement accept to select items from the current inner Iterator.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
class Positive extends FilterIterator { public function accept(): bool { /* ... */ } }Subclass this abstract wrapper and implement accept to select items from the current inner Iterator. A rejected item is skipped during traversal; accepted items retain their original keys and values. Inspect the inner cursor without advancing it inside accept.
class Positive extends FilterIterator { public function accept(): bool{return $this->getInnerIterator()->current()>0;} }
$it=new Positive(new ArrayIterator(["zero"=>0,"yes"=>2,"no"=>-1])); echo json_encode(iterator_to_array($it));
{"yes":2}
Examples
<?php
class Positive extends FilterIterator { public function accept(): bool{return $this->getInnerIterator()->current()>0;} }
$it=new Positive(new ArrayIterator(["zero"=>0,"yes"=>2,"no"=>-1])); echo json_encode(iterator_to_array($it));
Result
{"yes":2}