我可以通过引用方法访问多维数组中的任何位置.我可以改变它的价值.例如:
$conf = array( 'type' => 'MysqL','conf' => array( 'name' => 'mydatabase','user' => 'root','pass' => '12345','host' => array( '127.0.0.1','88.67.45.123','129.34.123.55' ),'port' => '3306' ) ); $value = & $this->getFromArray('type.conf.host'); $value = '-- changed ---'; // result $conf = array( 'type' => 'MysqL','host' => '-- changed ---' 'port' => '3306' ) );
但是,我不能破坏该部分:
// normally success unset($conf['type']['conf']['host']); // fail via reference $value = & $this->getFromArray('type.conf.host'); unset($value);
有解决方案吗?
好的,我认为更好的答案.为了取消设置,你应该获得对容器数组的引用,然后取消设置数组中的元素;
即
$value = & $this->getFromArray('type.conf'); unset $value['host'];