深入php define()函数以及defined()函数的用法详解


Posted in PHP onJune 05, 2013

The define() function defines a constant.
define()函数的作用是:定义一个常量。
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]”和“数字[number]”;

Syntax
语法

define(name,value,case_insensitive)

Parameter参数 Description描述
name Required. Specifies the name of the constant必要参数。指定常量的名称
value Required. Specifies the value of the constant必要参数。指定常量的值
case_insensitive Optional. Specifies whether the constant name should be case-insensitive. If set to TRUE, the constant will be case-insensitive. Default is FALSE (case-sensitive)可选参数。指定常量的名称是否是不区分大小写的[case-insensitive]。如果设置为True,则不区分字母大小写;如果设置为False,则区分字母大小写。默认值是:False

Example 1
案例1
Define a case-sensitive constant:
指定一个常量(区分大小写):

<?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:
指定一个常量(不区分大小写):
<?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()函数的作用是:检查一个常量是否存在。

Returns TRUE if the constant exists, or FALSE otherwise.
如果该常量存在,则返回True;如果不存在,则返回False。

Syntax
语法

defined(name)

Parameter参数 Description描述
name Required. Specifies the name of the constant to check必要参数。指定常量对象的名称

Example
案例

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

The output of the code above will be:
上述代码将输出下面的结果:
1
PHP 相关文章推荐
不用数据库的多用户文件自由上传投票系统(3)
Oct 09 PHP
sourcesafe管理phpproj文件的补充说明(downmoon)
Apr 11 PHP
连接到txt文本的超链接,不直接打开而是点击后下载的处理方法
Jul 01 PHP
php面向对象全攻略 (十四) php5接口技术
Sep 30 PHP
基于php设计模式中单例模式的应用分析
May 15 PHP
php预定义变量使用帮助(带实例)
Oct 30 PHP
PHP使用Session遇到的一个Permission denied Notice解决办法
Jul 30 PHP
php绘图之在图片上写中文和英文的方法
Jan 24 PHP
Laravel5.1数据库连接、创建数据库、创建model及创建控制器的方法
Mar 29 PHP
Nginx环境下PHP flush失效的解决方法
Oct 19 PHP
thinkphp5引入公共部分header、footer的方法详解
Sep 14 PHP
实例说明js脚本语言和php脚本语言的区别
Apr 04 PHP
基于PHP array数组的教程详解
Jun 05 #PHP
深入php list()函数的详解
Jun 05 #PHP
深入php var_dump()函数的详解
Jun 05 #PHP
php数组(array)输出的三种形式详解
Jun 05 #PHP
php set_time_limit()函数的使用详解
Jun 05 #PHP
基于PHP文件操作的详解
Jun 05 #PHP
深入探讨:PHP使用数据库永久连接方式操作MySQL的是与非
Jun 05 #PHP
You might like
ASP和PHP都是可以删除自身的
2007/04/09 PHP
PHP中call_user_func_array()函数的用法演示
2012/02/05 PHP
编译PHP报错configure error Cannot find libmysqlclient under usr的解决方法
2014/06/27 PHP
thinkphp自带验证码全面解析
2016/09/18 PHP
HTML中Select不用Disabled实现ReadOnly的效果
2008/04/07 Javascript
javaScript array(数组)使用字符串作为数组下标的方法
2013/11/19 Javascript
JS连连看源码完美注释版(推荐)
2013/12/09 Javascript
javascript基于HTML5 canvas制作画箭头组件
2014/06/25 Javascript
BootStrap Table 获取同行不同列元素的方法
2016/12/19 Javascript
完美解决node.js中使用https请求报CERT_UNTRUSTED的问题
2017/01/08 Javascript
微信浏览器禁止页面下拉查看网址实例详解
2017/06/28 Javascript
使用ng-packagr打包Angular的方法示例
2018/09/21 Javascript
详解key在Vue列表渲染时究竟起到了什么作用
2019/04/20 Javascript
微信小程序-可移动菜单的实现过程详解
2019/06/24 Javascript
python实现进程间通信简单实例
2014/07/23 Python
对Python进行数据分析_关于Package的安装问题
2017/05/22 Python
Python3处理HTTP请求的实例
2018/05/10 Python
Python3编码问题 Unicode utf-8 bytes互转方法
2018/10/26 Python
解决vscode python print 输出窗口中文乱码的问题
2018/12/03 Python
Python 数据库操作 SQLAlchemy的示例代码
2019/02/18 Python
Python3.5 + sklearn利用SVM自动识别字母验证码方法示例
2019/05/10 Python
python requests模拟登陆github的实现方法
2019/12/26 Python
python读取tif图片时保留其16bit的编码格式实例
2020/01/13 Python
基于CSS3特效之动画:animation的应用
2013/05/09 HTML / CSS
浅谈css3中calc在less编译时被计算的解决办法
2017/12/04 HTML / CSS
GNC健安喜美国官网:美国第一营养品牌
2016/07/22 全球购物
俄罗斯连接商品和买家的在线平台:goods.ru
2020/11/30 全球购物
中专生毕业自我鉴定
2013/11/01 职场文书
大学本科毕业生的自我鉴定
2013/11/26 职场文书
中英文自我评价常用句型
2013/12/19 职场文书
请假条的格式
2014/04/11 职场文书
2015年度护士个人工作总结
2015/04/09 职场文书
2016年清明节寄语
2015/12/04 职场文书
MySQL 使用自定义变量进行查询优化
2021/05/14 MySQL
MySQL修改默认引擎和字符集详情
2021/09/25 MySQL
OpenCV实现常见的四种图像几何变换
2022/04/01 Python