- reset: documentation ( source)
- key: documentation ( source)
- next: documentation ( source)
- current: documentation ( source)
<?php
class It implements Iterator
{
private $arr = [1,2,3];
public function key()
{
echo __METHOD__ . "\n";
return key($this->arr);
}
public function current()
{
echo __METHOD__ . "\n";
return current($this->arr);
}
public function rewind()
{
echo __METHOD__ . "\n";
reset($this->arr);
}
public function next()
{
echo __METHOD__ . "\n";
next($this->arr);
}
public function valid()
{
echo __METHOD__ . "\n";
return key($this->arr) !== null;
}
}
$it = new It;
foreach ($it as $k => $v) {}