Skip to content

Instantly share code, notes, and snippets.

@zhuanxuhit
Created October 27, 2016 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuanxuhit/4fd1e39bb86c5f58f6f9ea2956c10906 to your computer and use it in GitHub Desktop.
Save zhuanxuhit/4fd1e39bb86c5f58f6f9ea2956c10906 to your computer and use it in GitHub Desktop.
<?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