包括阵列文件 [英] Include file in array

查看:118
本文介绍了包括阵列文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code

$__routes = array(

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

);

和我有这样的使用example.php文件

and i have example.php file like this

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

我想包括在$ __路线阵

I want to include example.php file in "$__routes array"

有得像

$__routes = array(

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

include 'example.php';

);

请我该怎么办呢?

推荐答案

如果不改变使用example.php。每个文件必须是有效的PHP code自身,因为只包括发生在运行时(即当达到code这个确切的行),而不是(即当文件被加载)分析时

Not without changing example.php. Each file must be valid PHP code on its own, because the include only happens at runtime (i.e. when this exact line of code is reached), not at parse time (i.e. when the file is loaded)

一个办法来完成你需要的是什么

One way to accomplish what you need would be

使用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');

这篇关于包括阵列文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆