接口摘要 ArrayAccess { /* 方法 */ 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 ) }
举个例子
成都创新互联主营恒山网站建设的网络公司,主营网站建设方案,手机APP定制开发,恒山h5小程序制作搭建,恒山网站营销推广欢迎恒山等地区企业咨询
class Test implements ArrayAccess { private $testData = []; public function offsetExists($offset) { echo 'call ' . __METHOD__ . "\r\n"; return isset($this->testData[$offset]); } public function offsetGet($offset) { echo 'call ' . __METHOD__ . "\r\n"; return $this->testData[$offset]; } public function offsetSet($offset, $value) { echo 'call ' . __METHOD__ . "\r\n"; return $this->testData[$offset] = $value; } public function offsetUnset($offset) { echo 'call ' . __METHOD__ . "\r\n"; unset($this->testData[$offset]); } }
$obj = new Test();
if (!isset($obj['name'])) { //call Test::offsetExists
$obj['name'] = 'zhangsan'; //call Test::offsetSet
}
echo $obj['name'] . "\r\n"; //call Test::offsetGet
var_dump($obj);
$obj['age'] = 18; //call Test::offsetSet
echo $obj['age'] . "\r\n"; //call Test::offsetGet
unset($obj['address']); //call Test::offsetUnset
标题名称:ArrayAccess(数组式访问)接口
当前链接:https://www.cdcxhl.com/article18/pohpdp.html
成都网站建设公司_创新互联,为您提供网站策划、、静态网站、网站制作、品牌网站建设、企业建站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联