<?php class A { public $data = [1,2,3,4,5]; public function __construct() { next($this->data); } public function getIter() { foreach ($this->data as $key => $value) { yield $key => $value; } } } $a = new A; $gen = $a->getIter(); var_dump(current($a->data)); foreach ($gen as $key => $value) { var_dump($value); } var_dump(current($a->data));
You have javascript disabled. You will not be able to edit any code.