note 112729 added to generator.send
| From: | sfroelich01 at sp dot gm dot ail dot am dot com | Date: | Wed, 17 Jul 2013 12:11:43 +0000 |
| Subject: | note 112729 added to generator.send | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195654@lists.php.net to get a copy of this message | ||
Reading the example, it is a bit difficult to understand what exactly to do with this. The example
below is a simple example of what you can do this.
<?php
function nums() {
for ($i = 0; $i < 5; ++$i) {
//get a value from the caller
$cmd = (yield $i);
if($cmd == 'stop')
return;//exit the function
}
}
$gen = nums();
foreach($gen as $v)
{
if($v == 3)//we are satisfied
$gen->send('stop');
echo "{$v}\n";
}
//Output
0
1
2
3
?>
----
Server IP: 69.147.83.199
Probable Submitter: 41.222.234.6
----
Manual Page -- http://php.net/manual/en/generator.send.php
Edit -- https://master.php.net/note/edit/112729
Del: integrated -- https://master.php.net/note/delete/112729/integrated
Del: useless -- https://master.php.net/note/delete/112729/useless
Del: bad code -- https://master.php.net/note/delete/112729/bad+code
Del: spam -- https://master.php.net/note/delete/112729/spam
Del: non-english -- https://master.php.net/note/delete/112729/non-english
Del: in docs -- https://master.php.net/note/delete/112729/in+docs
Del: other reasons-- https://master.php.net/note/delete/112729
Reject -- https://master.php.net/note/reject/112729
Search -- https://master.php.net/manage/user-notes.php