Generator::send

(PHP 5 >= 5.5.0, PHP 7)

Generator::send锟斤拷锟斤拷锟斤拷锟斤拷锟叫达拷锟斤拷一锟斤拷值

说锟斤拷

public Generator::send ( mixed $value ) : mixed

锟斤拷锟斤拷锟斤拷锟斤拷锟叫达拷锟斤拷一锟斤拷值锟斤拷锟斤拷锟揭碉拷锟斤拷 yield 锟斤拷锟绞斤拷慕锟斤拷锟斤拷然锟斤拷锟斤拷锟街达拷锟斤拷锟斤拷锟斤拷锟斤拷锟�

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 yield 锟斤拷锟绞斤拷锟斤拷锟矫达拷诖锟斤拷锟街抵帮拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷械锟斤拷锟揭伙拷锟� yield 锟斤拷锟绞斤拷锟紸s such it is not necessary to "prime" PHP generators with a Generator::next() call (like it is done in Python).

锟斤拷锟斤拷

value

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷锟斤拷锟街碉拷锟斤拷岜伙拷锟轿拷锟斤拷锟斤拷锟斤拷锟角帮拷锟斤拷诘锟� yield 锟侥凤拷锟斤拷值

锟斤拷锟斤拷值

锟斤拷锟斤拷锟斤拷锟缴碉拷值锟斤拷

锟斤拷锟斤拷

Example #1 锟斤拷 Generator::send() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫达拷值

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

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

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

Hello world!