class myIterator implements Iterator
{
private $var = array(1, 2, 3, 4, 5);
public function __construct(){}
public function rewind()
{
reset($this->var);
}
public function current()
{
return current($this->var);
}
public function key()
{
return key($this->var);
}
public function next()
{
return next($this->var);
}
public function valid()
{
return ($this->current() !== false);
}
}
$it = new myIterator;
foreach($it as $key => $value) {
echo "$key=>$value
";
}