- var_dump: documentation ( source)
- get_object_vars: documentation ( source)
<?php
class values implements IteratorAggregate
{
protected $iterator = null;
protected $data = null;
public function __construct($data) {
$this->data = $data;
}
public function getIterator() {
if (null === $this->iterator){
if(is_array($this->data)) {
$this->iterator = new ArrayObject($this->data);
} else if(is_object($objOrArr)) {
$this->iterator = new ArrayObject(get_object_vars($this->data));
} else {
throw new Exception('$objOrArray is neither an array or an object');
}
}
return $this->iterator;
}
}
$values = new values(new DateTime());
for ($i = 0; $i < 100; $i++){
foreach($values as $k => $v) {
var_dump($k, $v);
}
}