Php –常数

[rps-include post=6522]

[rps-include post = 6522]

We have mainly worked with variables up to now. In most situations we need to use variables. But there are some exceptions where we need more reliable and constant values those will not changed during the execution of the applications. Php provides the constant type. Constants are designed to not changed during the application’s execution.

到目前为止,我们主要处理变量。 在大多数情况下,我们需要使用变量。 但是有一些例外,我们需要更可靠,更恒定的值,这些值在应用程序执行期间不会更改。 Php提供常量类型。 常量被设计为在应用程序执行期间不更改。

定义常数 (Define Constant)

We will define constants with define function. We will provide the name of the constant and the value the constant will refer. In this example we will define Pi number as constant because it can not be changed because of its mathematical meaning and position.

我们将使用define函数定义常量。 我们将提供常量的名称和常量将引用的值。 在此示例中,我们将Pi编号定义为常数,因为由于其数学含义和位置而无法更改。

define("PI",3.14);

echo "Pi number is ".PI;

As a general habit constants  generally defined with the uppercase letters. We can not only define numeric constants also string constants like below.

一般习惯,常量通常用大写字母定义。 我们不仅可以定义数字常量,还可以定义字符串常量,如下所示。

define("SITE","www.poftut.com");

[rps-include post=6522]

[rps-include post = 6522]

LEARN MORE  C Constants and Define Preprocessor
了解更多C常量并定义预处理器

翻译自: https://www.poftut.com/php-constant/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值