- reset: documentation ( source)
- key: documentation ( source)
- range: documentation ( source)
- next: documentation ( source)
- current: documentation ( source)
<?php
class Gen implements Iterator {
private $myArray;
public function __construct( $n ) {
$this->myArray = range(0,$n-1);
}
function rewind() {
return reset($this->myArray);
}
function current() {
return current($this->myArray);
}
function key() {
return key($this->myArray);
}
function next() {
return next($this->myArray);
}
function valid() {
return key($this->myArray) !== null;
}
}
$gen = new Gen(3);
// iterable object can be used in foreach
foreach ($gen as $g) {
echo $gen->current();
}