note 83087 added to function.next
| From: | adityabhai | Date: | Fri, 09 May 2008 12:14:14 +0000 |
| Subject: | note 83087 added to function.next | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139213@lists.php.net to get a copy of this message | ||
<?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);
}
public function getPrev () {
self::setCurrent($this->curr);
return prev($this->all);
}
}
?>
Demo Example:
<?php
$steps = new Steps();
$steps->add('1');
$steps->add('2');
$steps->add('3');
$steps->add('4');
$steps->add('5');
$steps->add('6');
$steps->setCurrent('4');
echo $steps->getCurrent()."<br />";
echo $steps->getNext()."<br />";
echo $steps->getPrev()."<br />";
$steps->setCurrent('2');
echo $steps->getCurrent()."<br />";
echo $steps->getNext()."<br />";
echo $steps->getPrev()."<br />";
?>
----
Server IP: 59.162.86.33
Probable Submitter: 122.169.25.81
----
Manual Page -- http://www.php.net/manual/en/function.next.php
Edit -- https://master.php.net/note/edit/83087
Del: integrated -- https://master.php.net/note/delete/83087/integrated
Del: useless -- https://master.php.net/note/delete/83087/useless
Del: bad code -- https://master.php.net/note/delete/83087/bad+code
Del: spam -- https://master.php.net/note/delete/83087/spam
Del: non-english -- https://master.php.net/note/delete/83087/non-english
Del: in docs -- https://master.php.net/note/delete/83087/in+docs
Del: other reasons-- https://master.php.net/note/delete/83087
Reject -- https://master.php.net/note/reject/83087
Search -- https://master.php.net/manage/user-notes.php