The
KeyedIterator<Tk, Tv> interface ¶
(HHVM >= 2.5)
Introduction ¶
Interface for external iterators or objects that can be iterated
themselves internally.
Interface synopsis ¶
KeyedIterator<Tk, Tv> extends KeyedTraversable<Tk,
Tv> extends Iterator<Tv> {
/* Methods */
/* Inherited methods
*/
}
Examples ¶
Example
#1 Basic usage
<?hh
class DuplicateStrIterator implements KeyedIterator<string, string> {
protected $it = 0;
public function current() {
return $this->it;
}
public function key() {
return chr(65 + ($this->it % 5));
}
public function next() {
$this->it++;
}
public function rewind() {
$this->it = 0;
}
public function valid() {
return $this->it < 10;
}
}
$it = new DuplicateStrIterator;
foreach($it as $key => $value) {
var_dump($key, $value);
echo "\n";
}
class DuplicateStrIterator implements KeyedIterator<string, string> {
protected $it = 0;
public function current() {
return $this->it;
}
public function key() {
return chr(65 + ($this->it % 5));
}
public function next() {
$this->it++;
}
public function rewind() {
$this->it = 0;
}
public function valid() {
return $this->it < 10;
}
}
$it = new DuplicateStrIterator;
foreach($it as $key => $value) {
var_dump($key, $value);
echo "\n";
}
The above example will output something similar to:
string(1) "A"
int(0)
string(1) "B"
int(1)
string(1) "C"
int(2)
string(1) "D"
int(3)
string(1) "E"
int(4)
string(1) "A"
int(5)
string(1) "B"
int(6)
string(1) "C"
int(7)
string(1) "D"
int(8)
string(1) "E"
int(9)
Table of Contents ¶
·
KeyedIterator<Tv>::key — Return the key of the current element
KeyedIterator<Tv>::key
(HHVM >= 2.5)
KeyedIterator<Tv>::key — Return the key of the current element
Description ¶
Returns the key of the current element.
Parameters ¶
This function has no parameters.
Return Values ¶
Errors/Exceptions ¶
Issues E_NOTICE on failure.
No comments:
Post a Comment