溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

define()與defined()函數(shù)如何在php中使用

發(fā)布時間:2020-12-22 15:02:21 來源:億速云 閱讀:166 作者:Leah 欄目:開發(fā)技術(shù)

今天就跟大家聊聊有關(guān)define()與defined()函數(shù)如何在php中使用,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

The define() function defines a constant.
define()函數(shù)的作用是:定義一個常量。

Constants are much like variables, except for the following differences:
常量[constant]與變量[variable]有很多相似的地方,因此,很容易混淆;下面,我們列舉一下常量[constant]與變量[variable]之間的不同點:
    A constant's value cannot be changed after it is set
    一個常量值在指定之后就不可以更改;
    Constant names do not need a leading dollar sign ($)
    設(shè)置常量時,不需要在前面加上“$”符號;
    Constants can be accessed regardless of scope
    常量可以被所有范圍的域訪問;
    Constant values can only be strings and numbers
    常量的值只能是“字符串[string]”和“數(shù)字[number]”;

Syntax
語法
define(name,value,case_insensitive)

Parameter
參數(shù)
Description
描述
nameRequired. Specifies the name of the constant
必要參數(shù)。指定常量的名稱
valueRequired. Specifies the value of the constant
必要參數(shù)。指定常量的值
case_insensitiveOptional. Specifies whether the constant name should be case-insensitive. If set to TRUE, the constant will be case-insensitive. Default is FALSE (case-sensitive)
可選參數(shù)。指定常量的名稱是否是不區(qū)分大小寫的[case-insensitive]。如果設(shè)置為True,則不區(qū)分字母大小寫;如果設(shè)置為False,則區(qū)分字母大小寫。默認(rèn)值是:False

Example 1
案例1
Define a case-sensitive constant:
指定一個常量(區(qū)分大小寫):

復(fù)制代碼 代碼如下:


<?phpdefine("GREETING","Hello you! How are you today?");echo constant("GREETING");?>


The output of the code above will be:
上述代碼將輸出下面的結(jié)果:

復(fù)制代碼 代碼如下:


Hello you! How are you today?


Example 2
案例2
Define a case-insensitive constant:
指定一個常量(不區(qū)分大小寫):

復(fù)制代碼 代碼如下:


<?phpdefine("GREETING","Hello you! How are you today?",TRUE);echo constant("greeting");?>


The output of the code above will be:
上述代碼將輸出下面的結(jié)果:

復(fù)制代碼 代碼如下:


Hello you! How are you today?


The defined() function checks whether a constant exists.
defined()函數(shù)的作用是:檢查一個常量是否存在。

Returns TRUE if the constant exists, or FALSE otherwise.
如果該常量存在,則返回True;如果不存在,則返回False。
Syntax
語法

復(fù)制代碼 代碼如下:


defined(name)

Parameter
參數(shù)
Description
描述
nameRequired. Specifies the name of the constant to check
必要參數(shù)。指定常量對象的名稱

Example
案例

復(fù)制代碼 代碼如下:


<?phpdefine("GREETING","Hello you! How are you today?");echo defined("GREETING");?>


The output of the code above will be:
上述代碼將輸出下面的結(jié)果:
1

看完上述內(nèi)容,你們對define()與defined()函數(shù)如何在php中使用有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI