Slightly more complex example, generating fibonacci sequence values with a count and offset:

[code]
function fibonacci($count, $offset=0) {
--$offset;

$prev = 0;
$current = 1;

if ($offset <= 0) {
--$count;
yield $prev;
} else {
for ($i = 0; $i < $offset; ++$i) {
$next = $prev + $current;
$prev = $current;
$current = $next;
}
}

for ($i = 0; $i $value) {
echo $i , ' -> ' , $value, PHP_EOL;
}

foreach (fibonacci(10,10) as $i => $value) {
echo $i , ' -> ' , $value, PHP_EOL;
}

foreach (fibonacci(10,20) as $i => $value) {
echo $i , ' -> ' , $value, PHP_EOL;
}
[/code]