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