Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
backend
php
oop
classes_objects
87iteration_Iterator.php
87iteration_Iterator.php
<?php /*Ako se ne stavi implements Iterator onda *ova skripta nece prikazivati nista */ class myIterator implements Iterator { private $position = 0; private $array = array( "firstelement", "secondelement", "lastelement", ); function __construct() { $this->position = 0; } function rewind() { var_dump(__METHOD__); $this->position = 0; } function next() { var_dump(__METHOD__); ++$this->position; } function valid() { var_dump(__METHOD__); return isset($this->array[$this->position]); } function current() { var_dump(__METHOD__); return $this->array[$this->position]; } function key() { var_dump(__METHOD__); return "key=".$this->position; } } $it = new myIterator; foreach($it as $key => $value) { var_dump($key, $value); echo $it->key(); echo $it->current(); echo "\n<hr/>"; } ?>
Reload page
Preview
W3C validation
Edit Code