Complete the code to implement the IteratorAggregate interface in the class.
<?php class MyCollection implements IteratorAggregate { private array $items = []; public function __construct(array $items) { $this->items = $items; } public function [1]() { return new ArrayIterator($this->items); } } ?>
Complete the code to return an iterator over the items array.
<?php
public function getIterator() {
return new [1]($this->items);
}
?>Fix the error in the method signature to properly implement IteratorAggregate.
<?php class Collection implements IteratorAggregate { public function [1](): Traversable { // method body } } ?>
Fill both blanks to create a class that implements IteratorAggregate and returns an iterator over a private array.
<?php class [1] implements IteratorAggregate { private array $data; public function __construct(array $data) { $this->data = $data; } public function getIterator(): [2] { return new ArrayIterator($this->data); } } ?>
Fill all three blanks to create a class that implements IteratorAggregate, stores items, and returns an iterator.
<?php class [1] implements IteratorAggregate { private array $[2]; public function __construct(array $items) { $this->[2] = $items; } public function getIterator(): [3] { return new ArrayIterator($this->[2]); } } ?>
