🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 实例 ``` <?php class demo implements arrayaccess { private $arr=[ 'a'=>'A', 'b'=>'B', ]; public function offsetExists($offset) { return isset($this->arr[$offset]); } public function offsetGet($offset) { return $this->arr[$offset]; } public function offsetSet($offset, $value) { $this->arr[$offset]=$value; } public function offsetUnset($offset) { unset($this->arr[$offset]); } } $demo = new demo(); var_dump($demo['a']); // 'A' unset($demo['a']); var_dump(isset($demo['a'])); // false $demo['c']='C'; var_dump($demo['c']); // 'C' ```