note 114776 added to class.iterator

From: Date: Fri, 04 Apr 2014 15:41:53 +0000
Subject: note 114776 added to class.iterator
Groups: php.notes 
Request: Send a blank email to php-notes+get-199185@lists.php.net to get a copy of this message
Examples of use <?php class myIterator implements Iterator { private $_array = array(); public function __construct(array $array) { $this->_array = $array; } public function rewind() { reset($this->_array); } public function current() { return current($this->_array); } public function key() { return key($this->_array); } public function next() { next($this->_array); } public function valid() { return $this->key() !== null; } } $it = new myIterator(array('foo_1' => 'bar_1','foo_2' => 'bar_2')); //example 1 : foreach foreach($it as $key => $value) { var_dump($key, $value); } //example 2 : while $it -> rewind(); while($it->valid()) { var_dump($it->key(), $it->current()); $it->next(); } //example 3 : for for($it->rewind();$it->valid();$it->next()) { var_dump($it->key(), $it->current()); } ?> ---- Server IP: 195.221.21.36 Probable Submitter: 83.112.207.72 ---- Manual Page -- http://php.net/manual/en/class.iterator.php Edit -- https://master.php.net/note/edit/114776 Del: integrated -- https://master.php.net/note/delete/114776/integrated Del: useless -- https://master.php.net/note/delete/114776/useless Del: bad code -- https://master.php.net/note/delete/114776/bad+code Del: spam -- https://master.php.net/note/delete/114776/spam Del: non-english -- https://master.php.net/note/delete/114776/non-english Del: in docs -- https://master.php.net/note/delete/114776/in+docs Del: other reasons-- https://master.php.net/note/delete/114776 Reject -- https://master.php.net/note/reject/114776 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199185) next »