将文件包含在数组中

2023-11-30

我有这个代码

$__routes = array(

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

);

我有这样的 example.php 文件

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

我想将 example.php 文件包含在“$__routes array”中

类似的东西

$__routes = array(

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

include 'example.php';

);

请问我该怎么做?


不更改 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');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将文件包含在数组中 的相关文章

随机推荐