Skip to content

Instantly share code, notes, and snippets.

@johnvilsack
Created June 20, 2013 21:31
Show Gist options
  • Save johnvilsack/5826836 to your computer and use it in GitHub Desktop.
Save johnvilsack/5826836 to your computer and use it in GitHub Desktop.
Iterator for PHP
function factory($strt, $stop, $plus = 1) {
for ($n = $strt; $n <= $stop; $n += $plus) {
yield $n;
}
}
foreach(factory(1,10) as $output) {
echo $output . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment