PHP arrayaccess Array Access interface in pre-defined interface

Source: Internet
Author: User

<?phpclass obj implements arrayaccess {private $container = array (); Public Function __construct () {$this-container = Array ("One" = 1, "    "= 2," three "= 3,);        The Public Function Offsetset ($offset, $value) {echo ' executes the object when the array is assigned the same value, this method ';        if (Is_null ($offset)) {$this, container [] = $value;        } else {$this-container [$offset] = $value;                The Public Function offsetexists ($offset) {echo ' executes the object when it is defined as an array, this method ';    Return Isset ($this-Container [$offset]);        The Public Function Offsetunset ($offset) {echo ' executes when an object is deleted as an array, this method ';    unset ($this-Container [$offset]);        The Public Function Offsetget ($offset) {echo ' takes an object as an array to fetch an element when executed, this method '; return Isset ($this COntainer [$offset])?    $this-Container [$offset]: null; }} $obj = new obj; Var_dump (isset ($obj ["")]) var_dump ($obj ["" "]) unset ($obj ["] ") Var_dump (Isset ( $obj ["n"])), $obj ["" ""] = "a value"; Var_dump ($obj ["" "]); $obj [' A '] = ' Append 1 '; $obj [' b '] = ' Append 2 '; $obj [' c '] = ' Append 3 ';p rint_r ($obj);

PHP arrayaccess Array Access interface in pre-defined interface

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.