svn: /phpdoc/en/trunk/language/oop5/ iterations.xml
| From: | David Tajchreber | Date: | Thu, 30 Dec 2010 10:10:51 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/oop5/ iterations.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-7584@lists.php.net to get a copy of this message | ||
dtajchreber Thu, 30 Dec 2010 10:10:51 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=306851
Log:
Patch submitted by anonymous person via online editor
Changed paths:
U phpdoc/en/trunk/language/oop5/iterations.xml
Modified: phpdoc/en/trunk/language/oop5/iterations.xml
===================================================================
--- phpdoc/en/trunk/language/oop5/iterations.xml 2010-12-30 10:03:10 UTC (rev 306850)
+++ phpdoc/en/trunk/language/oop5/iterations.xml 2010-12-30 10:10:51 UTC (rev 306851)
@@ -82,7 +82,6 @@
class MyIterator implements Iterator
{
private $var = array();
- private $index = 0;
public function __construct($array)
{
@@ -94,43 +93,35 @@
public function rewind()
{
echo "rewinding\n";
- $this->index = 0;
+ reset($this->var);
}
-
+
public function current()
{
- $k = array_keys($this->var);
- $var = $this->var[$k[$this->index]];
+ $var = current($this->var);
echo "current: $var\n";
return $var;
}
-
- public function key()
+
+ public function key()
{
- $k = array_keys($this->var);
- $var = $k[$this->index];
+ $var = key($this->var);
echo "key: $var\n";
return $var;
}
-
- public function next()
+
+ public function next()
{
- $k = array_keys($this->var);
- if (isset($k[++$this->index])) {
- $var = $this->var[$k[$this->index]];
- echo "next: $var\n";
- return $var;
- } else {
- echo "next:\n";
- return false;
- }
+ $var = next($this->var);
+ echo "next: $var\n";
+ return $var;
}
-
+
public function valid()
{
- $k = array_keys($this->var);
- $var = isset($k[$this->index]);
- echo "valid: {$var}\n";
+ $key = key($this->var);
+ $var = ($key !== NULL && $key !== FALSE);
+ echo "valid: $var\n";
return $var;
}
@@ -163,7 +154,7 @@
current: 3
key: 2
2: 3
-next: (no more)
+next:
valid:
]]>
</screen>