Created
October 27, 2016 03:16
-
-
Save zhuanxuhit/4fd1e39bb86c5f58f6f9ea2956c10906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getRange ($max = 10) { | |
for ($i = 1; $i < $max; $i++) { | |
$injected = yield $i; | |
if ($injected === 'stop') return; | |
} | |
} | |
$generator = getRange(PHP_INT_MAX); | |
foreach ($generator as $range) { | |
if ($range === 10000) { | |
$generator->send('stop'); | |
} | |
echo "Dataset {$range} <br>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment