phpincluderequire

Require multiple files


I am building a PHP application that uses a select menu to build email templates. The templates are broken into reusable parts (each is a separate html file). Is there an easy way to require multiple files with one expression? (my PHP is really rusty...)

Essentially I want to do something like:

function require_multi() {
    require_once($File1);
    require_once($File2);
    require_once($File3);
    require_once($File4);
}

Solution

  • Well, you could turn it into a function:

    function require_multi($files) {
        $files = func_get_args();
        foreach($files as $file)
            require_once $file;
    }
    

    Use like this:

    require_multi("one.php", "two.php", ..);
    

    However, if you're including classes, a better solution would be to use autoloading.