note 106561 deleted from function.next by thiago
| From: | thiago@php.net | Date: | Mon, 28 Nov 2011 12:01:46 +0000 |
| Subject: | note 106561 deleted from function.next by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184727@lists.php.net to get a copy of this message | ||
Note Submitter: bluexpres
----
is a recursive one.if current = last, return first
class Steps {
private $all;
private $count;
private $curr;
private $checknex;
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);
$this->nex = next($this->all);
if($this->checknex == "") return reset($this->all); else return
$this->checknex;
}
}
$steps = new Steps();
$steps->add('1');
$steps->add('2');
$steps->add('3');
$steps->add('4');
$steps->add('5');
$steps->add('6');
$steps->setCurrent('6');
echo $steps->getCurrent()."<br />";
echo $steps->getNext()."<br />";