yield

<?php
function test()
{
    for ($i = 1; $i < 10; $i++) {
        yield $i;
    }
}

$a = test();
foreach ($a as $k => $v){
    echo $v.PHP_EOL;
}
// or
while ($a->valid()) {
    echo $a->current().PHP_EOL;
    $a->next();
}

点赞

发表评论

邮箱地址不会被公开。 必填项已用*标注