<?php
$iterator = new ArrayIterator([1,3,5]);
$func = function() use ($iterator) {
return 0;
yield 2;
yield 4;
yield from $iterator;
};
$generator = $func();
foreach ($generator as $value) {
echo $value . PHP_EOL;
}
// only usable when return in Generator was reached
echo $generator->getReturn();