I have a iterator like this one:
http://nz.php.net/manual/en/class.iterator.php
And I was wondering how could I implement a method that runs when the objects have finished iterating.
For eg
foreach($objects as $object){
...
}
// here it's finished, and I want to automatically do something
Example for extending an Iterator:
class Foo extends ArrayIterator
{
public function valid() {
$result = parent::valid();
if (!$result) {
echo 'after';
}
return $result;
}
}
$x = new Foo(array(1, 2, 3));
echo 'before';
foreach ($x as $y) {
echo $y;
}
// output: before123after
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With