Battlefrisk Battlefrisk - 2 years ago 65
PHP Question

Include arrays with the same name from different files in PHP?

I am trying to figure out how I can include arrays that have the same name into my PHP file from two different files .

I know it's simple, but I can't seem to find the right search to get me to the solution.

I've been trying to reference the arrays such as

but that just isn't working.

Answer Source

Assuming both files have a $config array. If you want one resulting array:

$new = $config;

$new = array_merge($new, $config);

Or even two new arrays:

$config_1 = $config;

$config_2 = $config;

Another option would be a function:

function get_config($file) {
    return $config;

$config_1 = get_config('file1.php');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download