- var_dump: documentation ( source)
- reset: documentation ( source)
- next: documentation ( source)
<?php
class values implements Iterator
{
private $_data = null; // array or object
private $_keys = array();
private $_key = false;
public function __construct($data = null){
$this->_data = $data;
}
public function current(){
return $this->{"{$this->_key}"};
}
public function key(){
return $this->_key;
}
public function next(){
$this->_key = next($this->_keys);
}
public function rewind(){
$this->_keys = array();
foreach ($this->_data as $k => $v){
$this->_keys[] = $k;
}
$this->_key = reset($this->_keys);
}
public function valid(){
if (false === $this->_key){
return false;
}
return isset($this->{"{$this->_key}"});
}
}
$values = new values(new DateTime());
foreach($values as $k => $v) {
var_dump($k, $v);
}