Copy code The code is as follows:
interface ArrayAccess
boolean offsetExists($index)
mixed offsetGet($index)
void offsetSet($index, $newvalue)
void offsetUnset($index)
The following example shows how to use this interface. The example is not complete, but it is enough to understand. :-> {
private $db;//An object containing database access methods
function offsetExists($name) { return $this->db->userExists($name); } function offsetGet($name)
{
return $this->db->getUserId($name);
}
function offsetSet($name, $ id)
{
$this->db->setUserId($name, $id);
}
function offsetUnset($name)
{
$this- >db->removeUser($name);
}
}
$userMap = new UserToSocialSecurity();
print "John's ID number is " . $userMap['John'];
?>
In fact, when the $userMap['John'] search is executed, PHP calls the offsetGet() method, which then calls the database-related getUserId() method.
http://www.bkjia.com/PHPjc/322530.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/322530.html
TechArticle
Copy the code as follows: interface ArrayAccess boolean offsetExists($index) mixed offsetGet($index) void offsetSet($index , $newvalue) void offsetUnset($index) The following example shows...