I'm trying to implement OuterIterator interface on my class but I'm not sure what to use in the method getInnerIterator. I know it should return an Iterator but I'm not understanding in what circumstances it should return an InnerIterator although it is already has all the methods of the Iterator interface then why does it need an InnerIterator?
I'm totally lost with OuterIterator
class myouterIterator implements OuterIterator
{
/**
* Returns the inner Iterator for the current entry
*/
public $data = array(1,2,3,4,5,6,7,8,9,10);
public $position = 0;
public function getInnerIterator()
{
// What code should be place here
}
public function rewind()
{
$this->position = 0;
}
public function valid()
{
return isset($this->data[$this->position]);
}
public function key()
{
return $this->position;
}
public function current()
{
return $this->data[$this->position];
}
public function next()
{
++$this->position;
}
}
$OuterIt = new myouterIterator();
foreach($OuterIt as $key => $value)
{
echo $key, ' ', $value, '<br>';
}