define()與defined()函數(shù)怎么在php中使用-創(chuàng)新互聯(lián)

這篇文章將為大家詳細講解有關define()與defined()函數(shù)怎么在php中使用,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

創(chuàng)新互聯(lián)公司堅信:善待客戶,將會成為終身客戶。我們能堅持多年,是因為我們一直可值得信賴。我們從不忽悠初訪客戶,我們用心做好本職工作,不忘初心,方得始終。十年網(wǎng)站建設經(jīng)驗創(chuàng)新互聯(lián)公司是成都老牌網(wǎng)站營銷服務商,為您提供網(wǎng)站設計、成都網(wǎng)站制作、網(wǎng)站設計、HTML5、網(wǎng)站制作、高端網(wǎng)站設計、成都小程序開發(fā)服務,給眾多知名企業(yè)提供過好品質的建站服務。

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 ($)
設置常量時,不需要在前面加上“$”符號;
?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]。如果設置為True,則不區(qū)分字母大小寫;如果設置為False,則區(qū)分字母大小寫。默認值是:False

Example 1
案例1

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


復制代碼 代碼如下:


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



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


復制代碼 代碼如下:


Hello you! How are you today?



Example 2
案例2

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


復制代碼 代碼如下:


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



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


復制代碼 代碼如下:


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
語法


復制代碼 代碼如下:


defined(name)


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

Example
案例


復制代碼 代碼如下:


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



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


復制代碼 代碼如下:


1


關于define()與defined()函數(shù)怎么在php中使用就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

分享名稱:define()與defined()函數(shù)怎么在php中使用-創(chuàng)新互聯(lián)
鏈接地址:http://muchs.cn/article32/djgipc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供ChatGPT、服務器托管、網(wǎng)頁設計公司、Google做網(wǎng)站、面包屑導航

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設計