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