I am beginner in php
As i know Iterator is an interface to create iterator of a class and has 5 abstract methods. But i dont know when these methods are called when these methods perform their duty in foreach loop, what these methods do ?
All internet is inspected fot those 5 methods including php.net, sitepoint, etc.
Can anyone tell what does these methods do in Iterator interface in foreach loop?
Please explain it with the following piece of code as example.
class myClass implements Iterator{
public function rewind(){
//--What it will do ?
}
public function current(){
//--What it will do ?
}
public function key(){
//--What it will do ?
}
public function next(){
//--What it will do ?
}
public function valid(){
//--What it will do ?
}
}
$obj = new myClass();
foreach($obj as $value){
//--What is the duty or realtionship of rewind(), current(), key(), next(), valid() methods here in foreach loop ?
}
Can anyone tell in simple and easy words ?