Generator::getReturn

(PHP 7, PHP 8)

Generator::getReturn获取生成器的返回值

说明

public Generator::getReturn(): mixed

参数

此函数没有参数。

返回值

在生成器执行完成后,获取生成器的 return 值。

范例

示例 #1 Generator::getReturn() 示例

<?php

$gen
= (function() {
yield
1;
yield
2;

return
3;
})();

foreach (
$gen as $val) {
echo
$val, PHP_EOL;
}

echo
$gen->getReturn(), PHP_EOL;

以上例程会输出:

1
2
3

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top