children = $children; } public function rewind(): void { $this->active = $this->children; $this->key = 0; foreach ( $this->active as $key => $it ) { $it->rewind(); if ( !$it->valid() ) { unset( $this->active[$key] ); } } } public function valid(): bool { return (bool)$this->active; } public function next(): void { $this->key++; foreach ( $this->active as $key => $it ) { $it->next(); if ( !$it->valid() ) { unset( $this->active[$key] ); } } } #[\ReturnTypeWillChange] public function current() { $result = []; foreach ( $this->active as $it ) { $result[] = $it->current(); } return $result; } public function key(): int { return $this->key; } public function hasChildren(): bool { return (bool)$this->active; } public function getChildren(): ?RecursiveIterator { // The NotRecursiveIterator is used rather than a RecursiveArrayIterator // so that nested arrays don't get recursed. return new NotRecursiveIterator( new ArrayIterator( $this->current() ) ); } }