Skip to content

Commit

Permalink
Iterator and yield Generator;
Browse files Browse the repository at this point in the history
  • Loading branch information
sursir committed Nov 5, 2015
1 parent 67a75b2 commit 810d8e6
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion t.php
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
hello, test;
<?php

// class Bar implements IteratorAggregate
// {
// private function foo()
// {
// $i = 5;
// while ($i--)
// yield $i;
// }

// public function getIterator()
// {
// return $this->foo();
// }
// }

// $bar = new Bar();
// foreach ($bar as $item) {
// var_dump($item);
// }

function gen()
{
$i = 1;
while (true) {
yield $i += yield;
echo $i, "\n";
}
}

$gen = gen();
var_dump($gen->send(3));
$gen->next();
echo "----\n";
var_dump($gen->send(4));
$gen->next();
echo "----\n";
$gen->send(5);
$gen->next();
echo "----\n";
$gen->send(6);
$gen->next();
echo "----\n";
$gen->send(7);
$gen->next();
echo "----\n";

0 comments on commit 810d8e6

Please sign in to comment.