Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 22823 программиста и 1242 робота. Сейчас ищут 765 программистов ...
Приступая к работе

Generator::send - Send a value to the generator

Вернуться к: Generator

Generator::send

(PHP 5 >= 5.5.0, PHP 7)

Generator::sendSend a value to the generator

Описание

public mixed Generator::send ( mixed $value )

Sends the given value to the generator as the result of the current yield expression and resumes execution of the generator.

If the generator is not at a yield expression when this method is called, it will first be let to advance to the first yield expression before sending the value. As such it is not necessary to "prime" PHP generators with a Generator::next() call (like it is done in Python).

Список параметров

value

Value to send into the generator. This value will be the return value of the yield expression the generator is currently at.

Возвращаемые значения

Returns the yielded value.

Примеры

Пример #1 Using Generator::send() to inject values

<?php
function printer() {
    while (
true) {
        
$string yield;
        echo 
$string;
    }
}

$printer printer();
$printer->send('Hello world!');
$printer->send('Bye world!');
?>

Результат выполнения данного примера:

Hello world!
Bye world!



Вернуться к: Generator

© 2024 «PHP.RU — Сообщество PHP-Программистов»
Главная | Форум | Реклама на сайте | Контакты VIP Сувениры
Разработка компании ODware