其中一个很简单,如果你知道答案'问题......
以下是代码:
<?php require_once('assets/includes/config.php'); ?>
<?php require_once('assets/includes/functions.php'); ?>
config.php的相关内容......
$config = array(
"admin" => array(
"email" => "email@myaddress.com",
"display" => "My Address"
)
);
我的问题是我是否可以在第二个必需文件中引用配置变量? 我在functions.php中的内容是:
function send_admin_email($subject, $message) {
//Send Administration Email
$to = $config["admin"]["email"];
...
mail($to,$subject,$message,$headers);
}
这似乎不起作用。是因为我看不到config.php中设置的变量吗?
提前致谢
答案 0 :(得分:3)
将全局变量放入当前空间:
function send_admin_email($subject, $message) {
global $config ;
//Send Administration Email
$to = $config["admin"]["email"];
...
mail($to,$subject,$message,$headers);
}
答案 1 :(得分:1)
你可以像Jari建议的那样使用“global”,但我个人更愿意使用$ GLOBALS超全局来保持变量的范围:
function send_admin_email($subject, $message) {
//Send Administration Email
$to = $GLOBALS["config"]["admin"]["email"];
...
mail($to,$subject,$message,$headers);
}
编辑:用GLOBALS替换GLOBAL