(PHP 5 >= 5.5.0)
Generator::send — Send a value to the generator
Sends the given value to the generator as the result of the yield expression and resumes execution of the generator.
Generator::send() allows values to be injected into generator functions while iterating over them. The injected value will be returned from the yield statement and can then be used like any other variable within the generator function.
value
Exemplo #1 Using Generator::send() to inject values
<?php
function printer() {
while (true) {
$string = yield;
echo $string;
}
}
$printer = printer();
$printer->send('Hello world!');
?>
O exemplo acima irá imprimir:
Hello world!
Returns the yielded value.