PHP:所有页面的全局变量

时间:2011-10-13 21:37:55

标签: php global-variables constants

我需要一个可以从每个php页面调用的常量。 因此,例如,我在某处$APP_VERSION = "5.5"声明此常量。

然后我想从任何页面调用此变量。怎么做?

3 个答案:

答案 0 :(得分:1)

您可以定义一个包含所有常量的文件(例如costant.php),然后您必须使用include才能在每个脚本中检索它们。

答案 1 :(得分:1)

define('APP_VERSION', '5.5');

您可以将其放入要包含在您网页中的文件中。我就是这样你可以通过APP_VERSION

访问它
echo APP_VERSION; //outputs 5.5

答案 2 :(得分:1)

您可以使用define定义常量:

define('APP_VERSION', '5.5');

然后,在其他文件中:

echo APP_VERSION; // outputs '5.5'

http://php.net/manual/en/function.define.php