时间:2021-07-01 10:21:17 帮助过:4人阅读
interface ArrayAccess
boolean offsetExists($index)
mixed offsetGet($index)
void offsetSet($index, $newvalue)
void offsetUnset($index)
//Configuration Class class Configuration implements ArrayAccess { static private $config; private $configarray; private function __construct() { // init $this->configarray = array("Binzy"=>"Male", "Jasmin"=>"Female"); } public static function instance() { // if (self::$config == null) { self::$config = new Configuration(); } return self::$config; } function offsetExists($index) { return isset($this->configarray[$index]); } function offsetGet($index) { return $this->configarray[$index]; } function offsetSet($index, $newvalue) { $this->configarray[$index] = $newvalue; } function offsetUnset($index) { unset($this->configarray[$index]); } } $config = Configuration::instance(); print $config["Binzy"];
$config = Configuration::instance(); print $config["Binzy"]; $config['Jasmin'] = "Binzy's Lover"; // config 2 $config2 = Configuration::instance(); print $config2['Jasmin'];