我有一个名为config.php的php文件,在其中我以数组格式定义了应用程序设置,如下所示
<?php
return array(
'user' => 'jaison',
'email' => 'test@test.com',
);
?>
在主应用程序文件中,我需要将数组获取到一个变量中,这样它们就可以像这样使用。
<?php
$settings = include 'config.php';
?>
我想知道是否有其他方法可以做到这一点,而不是使用include。
我有一个名为config.php的php文件,在其中我以数组格式定义了应用程序设置,如下所示
<?php
return array(
'user' => 'jaison',
'email' => 'test@test.com',
);
?>
<?php
$settings = include 'config.php';
?>
不确定是否有其他方法可以不使用 include/include_once/require/require_once。
但是你可以使用类似于...
config.php
<?php
$settings = array(
'user' => 'jaison',
'email' => 'test@test.com',
);
?>
在主应用程序中使用
<?php
include 'config.php';
// Use $settings as if its defined above.
?>
由于您在系统中的所有页面中都使用此设置,因此我认为您可以使用常量。
例如:
define("USER","jaison");
define("EMAIL","test@test.com");
一旦您包含了配置文件,就可以在任何地方引用它。
例如:
echo USER;