Use Iterator, ArrayAccess, and Countable in 24php

Source: Internet
Author: User
: This article describes how to use Iterator, ArrayAccess, and Countable in 24php. For more information about PHP tutorials, see. The iterator is often used to facilitate data management when reading a large amount of data in the database.

 Fruits [$ this-> position];} // returns the current public function key () {return $ this-> position} // moves down an element public function next () {++ $ this-> position;} // move to the first element public function rewind () {$ this-> position = 0 ;} // determine whether there is a subsequent public function valid () {return isset ($ this-> fruits [$ this-> position + 1]);}

Make the data in the object accessible like an array

 Container = array ("one" => 1, "two" => 2, "three" => 3);} // assign a public function offsetSet ($ offset, $ value) {if (is_null ($ offset) {$ this-> container [] = $ value;} else {$ this-> container [$ offset] = $ value ;}} // whether a key has a public function offsetExists ($ offset) {return isset ($ this-> container [$ offset]);} // delete the public function offsetUnset ($ offset) {unset ($ this-> container [$ offset]);} // Obtain the public fu value corresponding to the key Nction offsetGet ($ offset) {return isset ($ this-> container [$ offset])? $ This-> container [$ offset]: null ;}$ obj = new obj (); var_dump (isset ($ obj ["two"]); var_dump ($ obj ["two"]); unset ($ obj ["two"]); var_dump (isset ($ obj ["two"]); $ obj ['two'] = "A value"; var_dump ($ obj ['two']); echo $ obj ['two']; $ obj [] = 'append 1'; $ obj [] = 'append 2'; $ obj [] = 'append 3'; var_dump ($ obj );

Allows an object to count attributes.

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


The above describes how to use Iterator, ArrayAccess, and Countable in 24php, including related content. if you are interested in PHP tutorials, you can help.

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.