note 79750 added to function.next
| From: | darkside at i dot ua | Date: | Tue, 11 Dec 2007 11:36:03 +0000 |
| Subject: | note 79750 added to function.next | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133360@lists.php.net to get a copy of this message | ||
This class implements simple operations with array
<?php
class Steps {
private $all;
private $count;
private $curr;
public function __construct () {
$this->count = 0;
}
public function add ($step) {
$this->count++;
$this->all[$this->count] = $step;
}
public function setCurrent ($step) {
reset($this->all);
for ($i=1; $i<=$this->count; $i++) {
if ($this->all[$i]==$step) break;
next($this->all);
}
$this->curr = current($this->all);
}
public function getCurrent () {
return $this->curr;
}
public function getNext () {
self::setCurrent($this->curr);
return next($this->all);
}
}
?>
usage example:
<?php
$steps = new Steps();
$steps->add('one');
$steps->add('two');
$steps->add('three');
$steps->setCurrent('one');
echo $steps->getCurrent()."<br />";
echo $steps->getNext()."<br />";
$steps->setCurrent('two');
echo $steps->getCurrent()."<br />";
echo $steps->getNext()."<br />";
?>
----
Server IP: 88.81.249.248
Probable Submitter: 77.109.22.91
----
Manual Page -- http://www.php.net/manual/en/function.next.php
Edit -- https://master.php.net/note/edit/79750
Del: integrated -- https://master.php.net/note/delete/79750/integrated
Del: useless -- https://master.php.net/note/delete/79750/useless
Del: bad code -- https://master.php.net/note/delete/79750/bad+code
Del: spam -- https://master.php.net/note/delete/79750/spam
Del: non-english -- https://master.php.net/note/delete/79750/non-english
Del: in docs -- https://master.php.net/note/delete/79750/in+docs
Del: other reasons-- https://master.php.net/note/delete/79750
Reject -- https://master.php.net/note/reject/79750
Search -- https://master.php.net/manage/user-notes.php