我有这段代码
$__routes = array(
"Home" => "index.php",
"Contact" => "contact.php",
"Register" => "register.php",
);
我有像这样的example.php文件
"Support" => "support.php",
"Success" => "success.php",
"Act" => "activate.php",
我想在“$ __ routes array”
中包含example.php文件有点像
$__routes = array(
"Home" => "index.php",
"Contact" => "contact.php",
"Register" => "register.php",
include 'example.php';
);
请问我该怎么做?
答案 0 :(得分:3)
不是没有改变example.php。每个文件本身必须是有效的PHP代码,因为include只发生在运行时(即达到这个确切的代码行),而不是在解析时(即文件加载时)
实现目标的一种方法是
<强>使用example.php 强>
return array(
"Support" => "support.php",
"Success" => "success.php",
"Act" => "activate.php"
);
主文件
$__routes = array(
"Home" => "index.php",
"Contact" => "contact.php",
"Register" => "register.php"
) + (include 'example.php');
答案 1 :(得分:0)
如果我正确理解你的意图,你可以将一个文件包含在另一个文件中并合并数组:
$merged_aray = array_merge($__routes, $array2);
$array2
等于:
"Support" => "support.php",
"Success" => "success.php",
"Act" => "activate.php"