- var_dump: documentation ( source)
- reset: documentation ( source)
- key: documentation ( source)
- next: documentation ( source)
- current: documentation ( source)
<?php
class MyArrayIter implements Iterator {
private $storage;
public function __construct(array $a) { $storage = $a; }
public function current() {
return current($this->storage);
}
public function key() {
return key($this->storage);
}
public function next() {
next($this->storage);
}
public function rewind() {
reset($this->storage);
}
public function valid() {
return key($this->storage) !== null;
}
}
$i = 1;
$a = [1,2,$i,4,5];
$iter = new MyArrayIter($a);
foreach($iter as &$v) {
$v = 1;
}
var_dump($a);
var_dump($iter);