Send An Argument To Generator

By Rahul Chavan

../_images/send_to_generator.png

When calling the method send() on a PHP generator, the result of the first yield keyword is the argument value. Then, it can be used to yield a specific result.

Upon usage on a foreach(), that generator will generate 2 values.

Generator::send() only accepts one argument.

See Also

PHP Features