溫馨提示×

溫馨提示×

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

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

php中defined()函數(shù)的使用方法

發(fā)布時間:2021-04-02 09:59:57 來源:億速云 閱讀:283 作者:小新 欄目:編程語言

這篇文章主要介紹php中defined()函數(shù)的使用方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

defined()是PHP中的內(nèi)置函數(shù),用于檢查是否存在常量,即是否定義了常量;語法格式“defined(name)”,參數(shù)name是要檢查的常量的名稱。如果常量存在,則返回TRUE,否則返回FALSE。

php defined()函數(shù)

defined() 函數(shù)檢查常量是否存在。

語法

defined(name)

name:規(guī)定要檢查的常量的名稱,不可省略。

返回值:如果常量存在,則返回 TRUE,否則返回 FALSE。

注意:此功能可用于PHP 4.0.0和更高版本。

示例1:

<?php
 define("constant_key", "value for the constant key"); 
echo defined("constant_key"); 
?>

輸出:

php中defined()函數(shù)的使用方法

示例2:定義常數(shù)后檢查條件是否成立。

<?php 
define("constant_key", "value for the constant key"); 
if(defined("constant_key")){ 
    echo "constant_key is defined"; 
}else{ 
    echo "constant_key is not defined"; 
} 
?>

輸出:

php中defined()函數(shù)的使用方法

示例3:在沒有定義常量的情況下檢查是否滿足條件。

<?php 
//define("constant_key", "value for the constant key"); 
if(defined("constant_key")){ 
    echo "constant_key is defined"; 
}else{ 
    echo "constant_key is not defined"; 
} 
?>

輸出:

php中defined()函數(shù)的使用方法

以上是“php中defined()函數(shù)的使用方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

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

php
AI