Skip to content

Instantly share code, notes, and snippets.

@stelt
Created March 31, 2017 08:05
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 stelt/5730c8e9767a6ba52979c97a7cc0ab63 to your computer and use it in GitHub Desktop.
Save stelt/5730c8e9767a6ba52979c97a7cc0ab63 to your computer and use it in GitHub Desktop.
<?php
function select($arr, $callback){
foreach ($arr as $value) {
if($callback($value))
yield $value;
}
}
$arr = [1, 2, 3, 4, 5, 6, 7, 8];
$select = select($arr, function($e){return $e % 2 == 0 ? true : false;});
$collect = collect($select, function($e){return $e * $e;});
foreach ($select as $val)
echo $val;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment