Traversing an operation that is primarily used to traverse an element, as with every element in an array, we can use iterators
Interface demo//here describes the interfaces that are provided to developers
{
Public function fn1 ();
Public function fn2 ();
Public function fn3 ();
}
Interface Demo2 extends demo//This step is to hide the specific implementation of the interface
{
Public function fn4 ();
}
Class Demo3 implements demo//users can call these methods on their own to implement the processing of these objects
{
Public Function Fn4 ()
{
echo ' function 2 ';
}
Public Function fn1 () {}
Public Function fn2 () {}
Public Function Fn3 () {}
}
$demo 3 = new Demo3 ();
$demo 3->fn4 ()
My understanding is that the program provides the interface, and we can define the algorithm to achieve it, so some people say it can improve efficiency.
The above understanding may not be full, I put the understanding of Daniel's advice, in fact, is also a simple thing
<span style= "Font-size:18px;color: #cc0000;" ><?php
class Myiterator implements iterator
{public
$position = 0;
Public $arr = Array (' One ', ' two ', ' three ', ' four ', ' five ', ' six ');
Public function __construct ()
{
$this->position = 0;
}
Public Function Rewind ()
{
var_dump (__method__);
$this->position = 0;
}
Public function current ()
{
var_dump (__method__);
return $this->arr[$this->position];
Public Function key ()
{
var_dump (__method__);
return $this->position;
}
Public function Next ()
{
var_dump (__method__);
+ + $this->position;
}
Public function valid ()
{
var_dump (__method__);
return Isset ($this->arr[$this->position]);
}
$it = new Myiterator;
foreach ($it as $key => $value)
{
var_dump ($key, $value);
echo "\ n";
} </span>