本文为joshua317原创文章,转载请注明:转载自joshua317博客 php 生成器 yield代码示例 - joshua317的博客
<?php
$start1 = memory_get_usage();
echo $start1.' bytes'.PHP_EOL;
$rangeNum = range(1, 100);
foreach ($rangeNum as $num) {
echo $num . PHP_EOL;
}
$end = memory_get_usage();
echo $end - $start1 .' bytes'.PHP_EOL;
function my_range($start, $limit) {
for ($i=$start; $i<=$limit; $i++) {
yield $i;
}
}
$start2 = memory_get_usage();
echo $start2.' bytes'.PHP_EOL;
$rangeNum2 = my_range(1, 100);
foreach ($rangeNum2 as $num) {
echo $num . PHP_EOL;
}
$end = memory_get_usage();
echo $end - $start2 .' bytes'.PHP_EOL;
本文为joshua317原创文章,转载请注明:转载自joshua317博客 php 生成器 yield代码示例 - joshua317的博客