note 123734 added to class.iteratoraggregate
| From: | MartinSpeer@php.net | Date: | Thu, 04 Apr 2019 08:40:39 +0000 |
| Subject: | note 123734 added to class.iteratoraggregate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210516@lists.php.net to get a copy of this message | ||
You can use yield from in getIterator in recent PHP 7 versions:
<?php
class Example implements \IteratorAggregate
{
protected $data = [];
public function __construct(array $data)
{
$this->data = $data;
}
public function getIterator()
{
yield from $this->data;
}
}
$test = new Example([1, 2, 3]);
foreach ($test as $node) {
echo $test, PHP_EOL;
}
/*
* Outputs:
*
* 1
* 2
* 3
*/ ?>
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 94.244.181.102)
----
Manual Page -- http://php.net/manual/en/class.iteratoraggregate.php
Edit -- https://master.php.net/note/edit/123734
Del: integrated -- https://master.php.net/note/delete/123734/integrated
Del: useless -- https://master.php.net/note/delete/123734/useless
Del: bad code -- https://master.php.net/note/delete/123734/bad+code
Del: spam -- https://master.php.net/note/delete/123734/spam
Del: non-english -- https://master.php.net/note/delete/123734/non-english
Del: in docs -- https://master.php.net/note/delete/123734/in+docs
Del: other reasons-- https://master.php.net/note/delete/123734
Reject -- https://master.php.net/note/reject/123734
Search -- https://master.php.net/manage/user-notes.php