Generally when you iterate over a set of data, you need to create a data, assuming that the array is large, it consumes a lot of performance, or even causes memory shortage.
// Fatal error:allowed Memory size of 134217728 bytes exhausted (tried to allocate + bytes) in E:\php\test\index.php on Line 5range(1, 100000000);
PHP5.5 implements the generator, each time an array element is returned with the yield keyword, and the execution function is paused, when executing the function next method, it will continue to execute from the last position of yield, as the following example (Hebei plastic Flooring | Shanghai kiddy), will only produce the intermediate variable $ I
functionXrange$start,$limit,$step= 1) { for($i=$start;$i<=$limit;$i+=$step) {yield$i; }} foreach(Xrange (1, 9, 1) as $number) { Echo"$number";}
Introduction to the PHP generator