<?php
class FooIterator extends ArrayIterator
{
public function key()
{
return $this->current()->getKey();
}
}
class Foo
{
public function __construct($key, $value)
{
$this->key = $key;
$this->value = $value;
}
public function getKey()
{
return $this->key;
}
public function getName()
{
return $this->name;
}
}
$arr = [
new Foo('aaa','value a'),
new Foo('bbb','value b'),
new Foo('ccc','value c'),
];
$iterator = new FooIterator($arr);
$arr = iterator_to_array($iterator);
dump(array_key_exists('bbb', $arr));
^ true