aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2014-09-28 21:41:51 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2014-11-07 14:19:29 +0100
commit0526af53cac741aaea2396cc19f4b395bcdb662f (patch)
tree4fcae202d72152d68313744eaf5adfa2d8edda24
parent30136ca74311c60043eb9c07180f165b9cc1c081 (diff)
downloadIterator-0526af53cac741aaea2396cc19f4b395bcdb662f.zip
Iterator-0526af53cac741aaea2396cc19f4b395bcdb662f.tar.gz
Iterator-0526af53cac741aaea2396cc19f4b395bcdb662f.tar.bz2
Fix key.
-rw-r--r--Counter.php13
1 files changed, 11 insertions, 2 deletions
diff --git a/Counter.php b/Counter.php
index 9796e2d..1798118 100644
--- a/Counter.php
+++ b/Counter.php
@@ -56,6 +56,13 @@ class Counter implements Iterator {
protected $_from = 0;
/**
+ * Current key.
+ *
+ * @var \Hoa\Iterator\Counter int
+ */
+ protected $_key = 0;
+
+ /**
* Current index.
*
* @var \Hoa\Iterator\Counter int
@@ -122,7 +129,7 @@ class Counter implements Iterator {
*/
public function key ( ) {
- return $this->_i;
+ return $this->_key;
}
/**
@@ -133,6 +140,7 @@ class Counter implements Iterator {
*/
public function next ( ) {
+ ++$this->_key;
$this->_i += $this->_step;
return;
@@ -146,7 +154,8 @@ class Counter implements Iterator {
*/
public function rewind ( ) {
- $this->_i = $this->_from;
+ $this->_key = 0;
+ $this->_i = $this->_from;
return;
}