在 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');
我想知道如何将两个不同文件中具有相同名称的数组包含到我的 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');