(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
Example #1 Using Generator::send() to inject values
<?php
function printer() {
while (true) {
$string = yield;
echo $string;
}
}
$printer = printer();
$printer->send('Hello world!');
?>
The above example will output:
Hello world!
Returns the yielded value.