PHP Advanced Programming (5/5) _php Tutorial

Source: Internet
Author: User
Arrayaccess Interface

The Arrayaccess interface is an object that behaves like a set of arrays, and defines four methods. The interface is summarized as follows:

arrayaccess {/**/abstract public boolean offsetexists ( Mixed $offset)abstract public mixed offsetget (mixed $offset)abstract  Public void offsetset (mixed $offset, mixed $value) Abstract  Public void offsetunset (mixed $offset)}

The Arrayaccess interface itself does not provide a function of calculating the number of heavy elements in the book group, if the number to be calculated can be achieved by implementing the Countble interface. This interface contains a count () method, and returns the number of elements.

 PhpclassMyArray implements arrayaccess{protected$_arr;  Publicfunction __construct () {$ This->_arr =Array (); }     Publicfunction Offsetset ($offset, $value) {$ This->_arr[$offset] =$value; }     Publicfunction Offsetget ($offset) {return$ This-_arr[$offset]; }     Publicfunction Offsetexists ($offset) {returnArray_key_exists ($offset, $ This-_arr); }     Publicfunction Offsetunset ($offset) {unset ($ This-_arr[$offset]); }} $MyArray=NewMyArray (); $MyArray [' First'] ='Test'; Echo $MyArray [' First'];unset ($MyArray [' First']);?>

Arratobject Class Introduction

The Arrayobject class is an implementation class for an Arrayaccess interface that provides iterative functionality and a number of very useful ways to sort and manipulate data.

ArrayobjectImplementsIteratoraggregate, Arrayaccess, Serializable,countable {/*Constants*/Const integerStd_prop_list = 1 ;Const integerArray_as_props = 2 ;/*Methods*/ Public__construct ([Mixed $input= [] [, int$flags= 0 [,string $iterator _class= "Arrayiterator" ]]] ) Publicvoid Append (Mixed $value ) PublicvoidAsort(void) PublicIntCount(void) Public ArrayExchangearray (Mixed $input ) Public Arraygetarraycopy (void) Publicint getflags (void) Publicarrayiterator getiterator (void) Public stringgetiteratorclass (void) PublicvoidKsort(void) PublicvoidNatcasesort(void) PublicvoidNatsort(void) PublicBOOL Offsetexists (Mixed $index ) Public MixedOffsetget (Mixed $index ) Publicvoid Offsetset (Mixed $index,Mixed $newval ) Publicvoid Offsetunset (Mixed $index ) Public string Serialize(void) Publicvoid SetFlags (int$flags ) Publicvoid Setiteratorclass (string $iterator _class ) PublicvoidUasort(Callable$cmp _function ) PublicvoidUksort(Callable$cmp _function ) Publicvoidunserialize(string $serialized )}

http://www.bkjia.com/PHPjc/815979.html www.bkjia.com true http://www.bkjia.com/PHPjc/815979.html techarticle The arrayaccess interface Arrayaccess interface is an object that behaves like a set of arrays, and defines four methods. The interface is summarized as follows: arrayaccess {/* Methods */Abstract public boolean OFFSE ...

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