这是我的类的一个示例,我在构造函数中定义了默认选项,我想用提供的任何选项替换它们。在构造函数中替换PHP
class Class{
private $options;
function __construct($options=null){
$this->options = array('option1'=>'value', 'option2'=>'value', ...);
array_replace(_recursive)($this->options,$options);
}
function showOpts(){
print_r($this->options);
}
}
$opt = array('newOpt'=>value ..);
$c = new Class($opt);
$c->showOpts();
当我打印选项的内容我得到的默认值没有任何更换。 我在做什么错?
你有一个错字(array_replace(_recursive)应该是array_replace_recursive') –