包括PHP中不同文件中具有相同名称的数组


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

我正试图弄清楚如何将具有相同名称的数组从两个不同的文件中包含到我的PHP文件中。

我知道这很简单,但我似乎找不到合适的搜索来找到解决方案。

我一直在尝试引用function_call(menu_config.$config)之类的数组,但这根本不起作用。

假设两个文件都有一个$config数组。如果你想要一个结果数组:

include('file1.php');
$new = $config;
include('file2.php');
$new = array_merge($new, $config);

甚至两个新阵列:

include('file1.php');
$config_1 = $config;
include('file2.php');
$config_2 = $config;

另一种选择是一个功能:

function get_config($file) {
    include($file);
    return $config;
}
$config_1 = get_config('file1.php');