Use iterator,arrayaccess and countable in 24php

Source: Internet
Author: User
iterators are often used by us to facilitate data management when reading large amounts of data in a database.

 
  fruits[$this->position];    }    Returns the current key public    function key () {        return $this->position    }    //Move down one element public    function next () {        + + $this->position;    }        Move to the first element of public    function rewind () {        $this->position = 0;    }    Determine if there is a subsequent element public    function valid () {        return isset ($this->fruits[$this->position+1]);}    }

Enables data in an object to be accessed like an array

 container = Array ("One" = 1, "One" = 2, "three" = 3); }//Assign Public function Offsetset ($offset, $value) {if (Is_null ($offset)) {$this->container        [] = $value;        } else {$this->container[$offset] = $value;    }}//A key exists public function offsetexists ($offset) {return isset ($this->container[$offset]);    }//Delete key value public function Offsetunset ($offset) {unset ($this->container[$offset]); }//Gets the value corresponding to the public function Offsetget ($offset) {return isset ($this->container[$offset])? $this->cont    ainer[$offset]:null; }} $obj = new obj (), Var_dump (Isset ($obj ["" "]), Var_dump ($obj [" ""]), unset ($obj ["]"), Var_dump (Isset ($obj [" "]), $obj [' both '] =" A value "; Var_dump ($obj [' both ']); Echo $obj [' both ']; $obj [] = ' Append 1 '; $obj [] = ' Append 2 '; $obj [] = ' AppE nd 3 '; var_dump ($obj);

Enables an object to count properties

 
  fruits);}    } $basket = new Basket (); Echo count ($basket);


The above describes the use of iterator,arrayaccess and countable in the 24php, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.