- array_keys: documentation ( source)
<?php
// fr Nikita's RFC
class DataContainer implements IteratorAggregate {
protected $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 (array_keys($dataContainer) as $key => $value) {
$dataContainer[$key] = ($value * -1);
}
// $this->data is now [-1, -2, -3]