php项目中的配置文件,php中的配置文件

您可以在某个地方定义此文件并将其包含或要求它。

require_once("path/to/file/config.php");

此文件中的任何变量都可以在脚本中访问

requires

/

includes

它。

或者可以使用define as:

define("TEST", "10"); //TEST holds constant 10

此外,如果希望在函数中访问它们,则有三个选项,在调用时将它们作为参数传递给函数,或在函数中声明为全局。

//example 1

require_once("path/to/file/config.php");

function testFunction($var){

echo $var." inside my function"; //echos contents of $var

}

//now lets say a variable $test = 10; was defined in config.php

echo $test; //displays "10" as it was defined in the config file. all is good

testFunction($test); //displays "10 inside my function" because $test was passed to function

//example 2

require_once("path/to/file/config.php");

function testFunction2(){

global $test;

echo $test; //displays "10" as defined in config.php

}

//example 3

define("TEST", "10");

echo TEST; // outputs "10"

//could have these constants defined in your config file as described and used above also!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值