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'];
注:本文章版权归文章作者与超越PHP网站所有,未经超越PHP网站同意,禁止任何商业转载。非盈利网站及个人网站转载请注明出处,谢谢合作!
新闻热点
疑难解答