ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[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' ```