php defined()函数
defined() 函数检查常量是否存在。
语法
defined(name)
name:规定要检查的常量的名称,不可省略。
返回值:如果常量存在,则返回 TRUE,否则返回 FALSE。
注意:此功能可用于PHP 4.0.0和更高版本。
示例1:
<?php
define("constant_key", "value for the constant key");
echo defined("constant_key");
?>
输出:

示例2:定义常数后检查条件是否成立。
<?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";
}
?>
输出:

示例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";
}
?>
输出:

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)