- print_r: documentation ( source)
- array_values: documentation ( source)
- current: documentation ( source)
<?php
class MyIter implements Iterator
{
private $a;
private $key = 0;
public function __construct(array $a)
{
$this->a = array_values($a);
}
public function key()
{
return $this->key;
}
public function rewind()
{
$this->key = 0;
}
public function valid()
{
echo __METHOD__, PHP_EOL;
return isset($this->a[$this->key]);
}
public function next()
{
echo __METHOD__, PHP_EOL;
$this->key++;
}
public function current()
{
echo __METHOD__, PHP_EOL;
return $this->a[$this->key];
}
}
$ilist = new MyIter(array('A', 'B', 'C', 'D'));
foreach ($ilist as $var) {
echo "var = $var\n";
echo "current = ", print_r(current($ilist), true), "\n";
}