- var_dump: documentation ( source)
<?php
class DataContainer implements IteratorAggregate {
public $data;
public function __construct(array $data) {
$this->data = $data;
}
public function getIterator() {
foreach ($this->data as $key => $value) {
yield $key => $value;
}
}
}
$dataContainer = new DataContainer([1, 2, 3]);
foreach ($dataContainer as $key => $value) {
$value *= -1;
$value->data[$key] = $value;
}
var_dump($dataContainer);