PHP Official Document Yield http://php.net/manual/zh/language.generators.overview.php
Reference: http://laravelacademy.org/post/4317.html
The generator provides an easier way to implement a simple object iteration, comparing the way that the definition class implements the Iterator interface, with significantly reduced performance overhead and complexity.
The generator allows you to write code in a foreach code block to iterate over a set of data without having to create an array in memory, which will limit your memory to a maximum or take up considerable processing time. Instead, you can write a generator function, just like a normal custom function, and the normal function returns only once differently, and the generator can yield multiple times as needed to generate values that need to be iterated.
$length=1000000;//Generatorforeach(Yieldtest ($length) as$v 1) {Echo$v 1;} functionyieldtest($length) { for($i=0;$i<$length;$i++) {yield$i.' Camel '; }}/* Iterator The following code throws an error: PHP Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate) bytes r/www/test/90/yield/demo01.php on line 38*/foreach(Iteratortest ($length) as$v 2) {Echo$v 2;} functioniteratortest($length) {$data= []; for($i=0;$i<$length;$i++) {$data[] =$i.' Camel '; }return$data;}
If you want to calculate a large amount of data in a specific way, such as manipulating Excel table data, it has more performance implications. At this point, we can use the generator to calculate and produce the subsequent values instantly, without taking up valuable memory space and using less memory.
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the PHP55 new feature yield generator, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.