PHP gets an array of arbitrary subscript keys for the previous prev and next next subscript value _php Tutorial

Source: Internet
Author: User
PHP gets the previous prev and next next subscript value of an array of arbitrary subscript keys


 $value) {$steps->add ($key);} $steps->setcurrent (3);//parameter is the key value Echo ' previous subscript: '. $steps->getprev (). "
"; Echo ' specifies the subscript: '. $steps->getcurrent ()."
"; Echo ' next subscript: '. $steps->getnext ()."
"; class Steps {private $all; Private $count; Private $curr; function __construct () {$this->count = 0; } function Add ($step) {$this->count++; $this->all[$this->count] = $step; } 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); } function GetCurrent () {return $this->curr; } function GetNext () {self::setcurrent ($this->curr); Return next ($this->all); } function GetPrev () {self::setcurrent ($this->curr); Return prev ($this->all); }}

Printing results:

Previous subscript: 2 subscript specified: 3 Next subscript: 4


http://www.bkjia.com/PHPjc/815135.html www.bkjia.com true http://www.bkjia.com/PHPjc/815135.html techarticle PHP gets an array of arbitrary subscript keys on the previous prev and next next subscript $value) {$steps->add ($key);} $steps->setcurrent (3);//parameter is key value echo previous subscript:. $steps->getprev (). " ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.