Generator

1. 语法

function myGenerator() 
{
    yield 'value1';
    yield 'value2';
    yield 'value3';
}

foreach (myGenerator() as $yieldedValue) {
    echo $yieldedValue, PHP_EOL;
}

//结果
value1
value2
value3

2. 使用环境

  1. 相当于多个return.

参考链接

http://oomusou.io/php/php-generator/

© 404mzk all right reserved,powered by Gitbook该文件修订时间: 2017-04-09 09:07:59

results matching ""

    No results matching ""