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 Gitbookhttp://blog.404mzk.com 该文件修订时间: 2016-12-12 22:55:35

results matching ""

    No results matching ""