PHP:所有页面的全局变量
我需要一个可以从每个 php 页面调用的常量。 因此,例如,我在某处声明此常量 $APP_VERSION = "5.5"
。
然后我想从任何页面调用这个变量。怎么办?
I need a constant that can be called from every php page.
So, for example, I declare this constant somewhere, $APP_VERSION = "5.5"
.
Then I would like to call this variable from any pages. how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将其放入将包含在页面中的文件中。这样你就可以通过
APP_VERSION
访问它You can put that in the file that would be included into your pages. I'n that way you'd access it by
APP_VERSION
您可以使用
define
定义常量:然后,在其他文件中:
http ://php.net/manual/en/function.define.php
You can define constants using
define
:Then, in other files:
http://php.net/manual/en/function.define.php
您可以定义一个文件(例如 costant.php),其中包含所有常量,然后您必须使用
include
才能在每个脚本中检索它们。You could define a file (for example costant.php) which will contains all your constants and then you have to use
include
to be able to retrieve them in every script.