Php-arrayaccess interface

Source: Internet
Author: User
An interface that provides the ability to access an object like an array.

Interface Summary

arrayaccess {    /* method *    /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)}

Example #1 Usage Examples

<?php class obj implements arrayaccess {private $container = array ();  Public Function __construct () {$this->container = array ("one" + = 1, "one")        = 2, "three" = 3,); Public Function Offsetset ($offset, $value) {if (Is_null ($offset)) {$this->containe            R[] = $value;            } else {$this->container[$offset] = $value;        }} Public Function offsetexists ($offset) {return isset ($this->container[$offset]);        Public Function Offsetunset ($offset) {unset ($this->container[$offset]); } Public Function Offsetget ($offset) {return isset ($this->container[$offset])? $this->container[        $offset]: null;    }} $obj = new obj;    Var_dump (Isset ($obj ["the"]);    Var_dump ($obj ["the"]);    unset ($obj ["the"]); Var_dump (Isset ($obj ["TWO "]));    $obj ["" "] =" A value ";    Var_dump ($obj ["the"]);    $obj [] = ' Append 1 ';    $obj [] = ' Append 2 ';    $obj [] = ' Append 3 '; Print_r ($obj);? >

The output of the above routines is similar to the following:

BOOL (TRUE) int (2) bool (FALSE) string (7) "A value" obj Object (    [container:obj:private]            = = Array ([one] = > 1            [three] = 3            [A] = A value            [0] = Append 1            [1] = Append 2            [2] = Append 3
  ))

Method List

arrayaccess::offsetexists-Check if an offset position exists

Arrayaccess::offsetget-gets the value of an offset position

arrayaccess::offsetset-setting the value of an offset position

arrayaccess::offsetunset-resets the value of an offset position

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