defined() 用于检测给定的常量是否被定义。
isset()
PHP defined() 用于检测一个给定的常量是否被定义,如果被检测的常量已定义则返回 TRUE,否则返回 FALSE。
语法:
bool defined( string name )
例子:
<?php define('CONSTANT', "你好!"); if(defined('CONSTANT')){ echo '常量 CONSTANT 已经被定义'; } else { echo '常量 CONSTANT 还未被定义'; } ?>
运行该例子输出:
常量 CONSTANT 已经被定义
参考阅读
- define():定义一个常量
- isset():检测变量是否设置
- is_array():检测变量是否是数组