PHP advanced programming (5/5) _ PHP Tutorial

Source: Internet
Author: User
PHP advanced programming (55 ). ArrayAccess interface the ArrayAccess interface is an array of objects and defines four methods. Interface Overview: ArrayAccess {* Methods * abstractpublicbooleanoffse ArrayAccess interface

The ArrayAccess interface is an array of objects and defines four methods. The interface is as follows:

ArrayAccess {/* Methods */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 does not provide the function of calculating the number of duplicate elements in a book group. to calculate the number, you can implement the Countble interface. This interface contains a count () method and returns the number of elements.

 _arr = array();    }    public function offsetSet($offset, $value)    {        $this->_arr[$offset] = $value;    }    public function offsetGet($offset)    {        return $this->_arr[$offset];    }    public function offsetExists($offset)    {        return array_key_exists($offset, $this->_arr);    }    public function offsetUnset($offset)    {        unset($this->_arr[$offset]);    }}$MyArray = new MyArray();$MyArray['first'] = 'test';echo $MyArray['first'];unset($MyArray['first']);?>

ArratObject class Introduction

The ArrayObject class is an implementation class of the ArrayAccess interface. It provides iteration functions and many useful methods for sorting and processing data.

ArrayObject implements IteratorAggregate , ArrayAccess , Serializable , Countable {/* Constants */const integer STD_PROP_LIST = 1 ;const integer ARRAY_AS_PROPS = 2 ;/* Methods */public __construct ([ mixed $input = [] [, int $flags = 0 [, string $iterator_class = "ArrayIterator" ]]] )public void append ( mixed $value )public void asort ( void )public int count ( void )public array exchangeArray ( mixed $input )public array getArrayCopy ( void )public int getFlags ( void )public ArrayIterator getIterator ( void )public string getIteratorClass ( void )public void ksort ( void )public void natcasesort ( void )public void natsort ( void )public bool offsetExists ( mixed $index )public mixed offsetGet ( mixed $index )public void offsetSet ( mixed $index , mixed $newval )public void offsetUnset ( mixed $index )public string serialize ( void )public void setFlags ( int $flags )public void setIteratorClass ( string $iterator_class )public void uasort ( callable $cmp_function )public void uksort ( callable $cmp_function )public void unserialize ( string $serialized )}

The ArrayAccess interface is an array of objects and defines four methods. Interface Overview: 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.