Last active
February 15, 2020 20:13
-
-
Save zonuexe/b6fcc03a198931f622433525c5ad899d to your computer and use it in GitHub Desktop.
ジェネレータで無限を手玉に取る修行 (2)
This file contains hidden or 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 fibonacci() | |
{ | |
$i = 0; | |
$j = 1; | |
while (true) { | |
yield $i; | |
[$i, $j] = [$j, $i + $j]; | |
} | |
} | |
var_dump(iterator_to_array(take(20, fibonacci()))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment