Autoregister model / library / helper I have an array $autoload:

$autoload['models'] = array();
$autoload['libraries'] = array();
$autoload['helpers'] = array('url', 'lang');


and in my controller I call each model / library / helper in autoload with this function:

private function auto_register() {
        global $autoload;

        foreach ($autoload as $type =&gt; $names) {
            foreach ($names as $name) {
                switch ($type) {
                    case 'libraries':
                        $this-&gt;{$name . '_library'} = call_user_func_array(array($this-&gt;load, "library"), array($name));
                        break;
                    case 'models':
                        $this-&gt;{$name . '_model'} = call_user_func_array(array($this-&gt;load, "model"), array($name));
                        break;
                    case 'helpers':
                        call_user_func_array(array($this-&gt;load, "helper"), array($name));
                        break;
                    default: '';
                        break;
                }
            }
        }
    }


Is there simple way to refactor this function? This is working as it is, but I'm looking for a more elegant solution.
For each name, the current logic checks the type. That's ugly.
It's better to rewrite this without a switch,
which turns out to be shorter too:

private function auto_register() {
    global $autoload;

    foreach ($autoload['libraries'] as $name) {
        $this-&gt;{$name . '_library'} = call_user_func_array(array($this-&gt;load, "library"), array($name));
    }
    foreach ($autoload['models'] as $name) {
        $this-&gt;{$name . '_model'} = call_user_func_array(array($this-&gt;load, "model"), array($name));
    }
    foreach ($autoload['helpers'] as $name) {
        call_user_func_array(array($this-&gt;load, "helper"), array($name));
   }
}