我怎样才能使这段代码更有效/更动态,所以如果我需要传递更多参数,它是动态的?
因为现在在这一点上有点乱,我喜欢我的代码干净简单:)
protected function getSettings()
{
$args = func_get_args();
switch (func_num_args()) {
case 1:
$set = (isset($this->settings[ $args[0] ]))
? $this->settings[ $args[0] ]
: array();
break;
case 2:
$set = (isset($this->settings[ $args[0] ][ $args[1] ]))
? $this->settings[ $args[0] ][ $args[1] ]
: array();
break;
case 3:
$set = (isset($this->settings[ $args[0] ][ $args[1] ][ $args[2] ]))
? $this->settings[ $args[0] ][ $args[1] ][ $args[2] ]
: array();
break;
case 4:
$set = (isset($this->settings[ $args[0] ][ $args[1] ][ $args[2] ][ $args[3] ]))
? $this->settings[ $args[0] ][ $args[1] ][ $args[2] ][ $args[3] ]
: array();
break;
case 5:
$set = (isset($this->settings[ $args[0] ][ $args[1] ][ $args[2] ][ $args[3] ][ $args[4] ]))
? $this->settings[ $args[0] ][ $args[1] ][ $args[2] ][ $args[3] ][ $args[4] ]
: array();
break;
default:
$set = $this->settings;
break;
}
return $set;
}