Por que esse código não imprimiu nada na tela?
Olá pessoal, quero saber por que esse script não imprime nada como, por exemplo:
0 => 2
1 => 4
2 => 6
3 => 8
4 => 10
Não imprime nada... Achei que iria sair algo como mencionei ali em cima, mais obtive uma tela em branco sem erros :( Espero que vocês possam me ajudar. Abraço!
<?php
class ObjectIterator implements Iterator{
private $obj;
private $count;
private $currentIndex;
function __construct($obj){
$this->obj = $obj;
$this->count = count($this->obj->data);
}
function rewind(){
$this->currentIndex = 0;
}
function valid(){
$this->currentIndex < $this->count;
}
function key(){
return $this->currentIndex;
}
function current(){
$this->obj->data[$this->currentIndex];
}
function next(){
$this->currentIndex++;
}
}
class Object implements IteratorAggregate{
public $data = array();
function __construct($in){
$this->data = $in;
}
function getIterator(){
return new ObjectIterator($this);
}
}
$myObject = new Object(array(2, 4, 6, 8, 10));
$myIterator = $myObject->getIterator();
for($myIterator->rewind(); $myIterator->valid(); $myIterator->next()){
$key = $myIterator->key();
$value = $myIterator->current();
echo $key ."=>". $value ."<br />";
}
?>Discussão (5)
Carregando comentários...