The PHP arrayaccess interface is also called an array-style access interface that provides the ability to access an object like an array.
The interface summary is as follows:
arrayaccess { //Get an offset position value abstract public mixed offsetget (mixed $offset) //Set an offset value for abstract publ IC void Offsetset (mixed $offset, mixed $value) //Check an offset position for the presence of an abstract public boolean offsetexists (mixed $o Ffset) //reset value of an offset position abstract public void Offsetunset (mixed $offset)}
Example Description:
data[$key]; /** * Add an array element as an object * * @access public * @param string array element key Name * @param mixed array element value * @retur N Mixed */Public function __set ($key, $value) {$this->data[$key] = $value; /** * Determines whether an array element is set in object mode * * @access public * @param array element Key Name * @return Boolean */Public funct Ion __isset ($key) {return isset ($this->data[$key]); /** * Delete an array element as an object * * @access public * @param array element Key Name */Public Function __unset ($key) { unset ($this->data[$key]); }/** * Adds an array of elements to the data array * * @access public * @abstracting arrayaccess * @param string offset position * @param mixed Element value */Public Function Offsetset ($offset, $value) {if (Is_null ($offset)) {$this-& Gt;data[] = $value; } else {$this->data[$offset] = $value; }}/** * Array to get data array specified position element * * @access public * @abstracting ARrayaccess * @param offset position * @return Mixed */Public Function Offsetget ($offset) {return $this ->offsetexists ($offset)? $this->data[$offset]: null; /** * Array to determine if the offset position element is set * * @access public * @abstracting arrayaccess * @param offset position * @return Boolean * Public Function offsetexists ($offset) {return isset ($this->data[$offset]); /** * Delete data array as array specify position element * * @access public * @abstracting arrayaccess * @param offset Position * * Public Function Offsetunset ($offset) {if ($this->offsetexists ($offset)) {unset ($this->data[$ Offset]); }}} $animal = new arrayandobjectaccess (); $animal->dog = ' dog '; Call arrayandobjectaccess::__set$animal[' pig '] = ' pig '; Call Arrayandobjectaccess::offsetsetvar_dump (Isset ($animal->dog)); Call Arrayandobjectaccess::__issetvar_dump (Isset ($animal [' pig ']); Call Arrayandobjectaccess::offsetexistsvar_dump ($animal->pIG); Call Arrayandobjectaccess::__getvar_dump ($animal [' dog ']); Call Arrayandobjectaccess::offsetgetunset ($animal [' dog ']); Call Arrayandobjectaccess::offsetunsetunset ($animal->pig); Call Arrayandobjectaccess::__unsetvar_dump ($animal [' pig ']); Call Arrayandobjectaccess::offsetgetvar_dump ($animal->dog); Call arrayandobjectaccess::__get?>
Above output:
Boolean true
Boolean true
String ' Pig ' (length=3)
String ' dog ' (length=3)
Null
Null
The above describes the Php-arrayaccess interface in detail, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.