- array_unshift: documentation ( source)
<?php
$a = [0,1,2,null,3];
foreach($a as $k => $v){
echo $v;
}
echo "\n";
class Test implements Iterator {
private $p = 0;
private $a = [0,1,2,null,3];
public function __construct() {
array_unshift( $this->a, 8 );
}
function rewind() {
$this->p = 0;
}
function current() {
return $this->a[$this->p];
}
function key() {
return $this->p;
}
function next() {
++$this->p;
}
function valid() {
return isset( $this->a[$this->p] );
}
}
$it = new Test;
foreach($it as $k => $v) {
echo $v;
}
?>