Created
October 5, 2019 05:28
-
-
Save caironm/c70aa936876176e00bc1747d2b02e7e8 to your computer and use it in GitHub Desktop.
Generator exemplo
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 meuGenerator(){ | |
yield 'valor1'; | |
yield 'valor2'; | |
yield 'valor3'; | |
} | |
foreach (meuGenerator() as $yieldValor) { | |
echo $yieldValor, PHP_EOL; | |
} | |
/* A saída será: | |
valor1 | |
valor2 | |
valor3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment