CakeFest 2024: The Official CakePHP Conference

Generator::current

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

Generator::currentyield した値を取得する

説明

public Generator::current(): mixed

パラメータ

この関数にはパラメータはありません。

戻り値

yield した値を返します。

add a note

User Contributed Notes 2 notes

up
1
gib-o-master
2 years ago
current() advances untouched generator, same as next(), it makes the first step/iteration. the following calls will not.

non-yielded value will be NULL
up
0
mrsoftware73 at gmail dot com
6 years ago
<?php
function gen_one_to_three() {
for (
$i = 1; $i <= 3; $i++) {
// Note that $i is preserved between yields.
yield $i;
}
}

$generator = gen_one_to_three();
foreach (
$generator as $value) {
echo
"regular : ".$value , PHP_EOL;
echo
"With current function : ".$generator->current(),PHP_EOL;
}
?>
To Top