淘先锋技术网

首页 1 2 3 4 5 6 7

PHP预定义接口之 ArrayAccess(数组访问式)

一个实现了这个接口的类就可以做到了

class FacadeCompany implements ArrayAccess

{

private $data;

public function offsetExists($offset)

{

// TODO: Implement offsetExists() method.

return isset($this->data[$offset]);

}

public function offsetGet($offset)

{

// TODO: Implement offsetGet() method.

return $this->data[$offset];

}

public function offsetSet($offset, $value)

{

// TODO: Implement offsetSet() method.

$this->data[$offset] = $value;

}

public function offsetUnset($offset)

{

// TODO: Implement offsetUnset() method.

unset($this->data[$offset]);

}

}