2

我有这个代码

$__routes = array(

"Home"                    => "index.php",
"Contact"                 => "contact.php",
"Register"                => "register.php",

);

我有这样的example.php文件

"Support"                 => "support.php",
"Success"                 => "success.php",
"Act"                     => "activate.php",

我想在“$__routes 数组”中包含 example.php 文件

有点像

$__routes = array(

"Home"                    => "index.php",
"Contact"                 => "contact.php",
"Register"                => "register.php",

include 'example.php';

);

请问我该怎么做?

4

2 回答 2

4

不是不改变example.php。每个文件本身必须是有效的 PHP 代码,因为包含只发生在运行时(即到达该确切代码行时),而不是在解析时(即加载文件时)

完成您需要的一种方法是

例子.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');
于 2013-01-23T23:00:16.530 回答
0

如果我正确理解您的意图,您可以将一个文件包含到另一个文件中并合并数组:

$merged_aray = array_merge($__routes, $array2);

其中$array2等于:

"Support"                 => "support.php",
"Success"                 => "success.php",
"Act"                     => "activate.php"
于 2013-01-23T22:59:49.240 回答