<?php class myData implements IteratorAggregate { public $property1 = "Public property one"; public $property2 = "Public property two"; public $property3 = "Public property three"; public function __construct() { $this->property4 = "last property"; } public function getIterator() { return new ArrayIterator($this); } } class myIterator implements Iterator { private $position = 0; private $array = array('one', 'two', 'three'); function rewind() { $this->position = 0; } function current() { return $this->array[$this->position]; } function key() { return $this->position; } function next() { ++$this->position; } function valid() { return isset($this->array[$this->position]); } } $renderFunction = function($iterator) { foreach($iterator as $key => $value) { echo "$key: $value\n"; foreach($iterator as $key => $value) { echo " $key: $value\n"; } } }; echo "-----IteratorAggregate-----\n"; $renderFunction(new myData); echo "\n-----Iterator-----\n"; $renderFunction(new myIterator);
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`