define
define()函数了解1(着重于效果的了解)
define()函数定义一个常量。
常量的特色:
常量相似变量,不同之处在于:在设定以后,常量的值无法更改常量名,不需要开头的美元符号($),效果域不影响对常量的拜访,常量值只能是字符串或数字。
define函数了解2(着重于参数了解)
语法
define(name,value,case_insensitive)
参数
描绘
name必需。规则常量的称号。//name参数为define函数的第一个参数,且为大写;
value必需。规则常量的值。//value的值一般为字符串或许数字
case_insensitive
可选。规则常量的称号是否对大小写灵敏。
若设置为true,则对大小写不灵敏。默认是false(大小写灵敏)。
define函数了解3(着重于实例了解)
问题1:一个大小写灵敏的常量:
define(“HF”,”HiFriend!”);//1.define函数怎么了解;
echoconstant(“HF”);//1.case_insensitive参数默认是false(大小写灵敏)2.constant函数怎么了解;3.constant内的参数怎么了解;
?>
输出成果为:HiFriend!
留意:符号输入准确,否则简单犯错;
define函数了解4
问题:2:一个大小写不灵敏的常量:
define(“HF”,”HiFriend!”,TRUE);//1.define函数怎么了解;2.define内的3个参数怎么了解;
echoconstant(“hf”);//1.echo函数怎么了解;2.constant函数怎么了解;3.constant函数输入时是否可以不区分大小写;4.constant函数内的参数怎么了解;
?>
输出的成果为:HiFriend!
PHPdefine()函数用法详解
Thedefine()functiondefinesaconstant.define()函数的作用是:定义一个常量。Constantsaremuchlikevariables,exceptforthefollowingdifferences:
常量[constant]与变量[variable]有很多相似的当地,因此,很简单混淆;下面,咱们罗列一下常量[constant]与变量[variable]之间的不同点:
?Aconstant’svaluecannotbechangedafteritisset一个常量值在指定之后就不能够更改;
?Constantnamesdonotneedaleadingdollarsign($)设置常量时,不需要在前面加上“$”符号;
?Constantscanbeaccessedregardlessofscope常量能够被一切范围的域拜访;
?Constantvaluescanonlybestringsandnumbers常量的值只能是“字符串[string]”和“数字[number]”;
Syntax语法
define(name,value,case_insensitive)
Parameter参数
Description描绘
name
Required.Specifiesthenameoftheconstant必要参数。指定常量的称号
value
Required.Specifiesthevalueoftheconstant必要参数。指定常量的值
case_insensitive
Optional.Specifieswhethertheconstantnameshouldbecase-insensitive.IfsettoTRUE,theconstantwillbecase-insensitive.DefaultisFALSE(case-sensitive)可选参数。指定常量的称号是否是不区别大小写的[case-insensitive]。假如设置为True,则不区别字母大小写;假如设置为False,则区别字母大小写。默认值是:False
Example1事例1Defineacase-sensitiveconstant:
指定一个常量(区别大小写):
Theoutputofthecodeabovewillbe:
上述代码将输出下面的成果:
Helloyou!Howareyoutoday?
Example2事例2Defineacase-insensitiveconstant:
指定一个常量(不区别大小写):
Theoutputofthecodeabovewillbe:
上述代码将输出下面的成果:
Helloyou!Howareyoutoday?
Thedefined()functioncheckswhetheraconstantexists.
defined()函数的作用是:检查一个常量是否存在。
ReturnsTRUEiftheconstantexists,orFALSEotherwise.
假如该常量存在,则返回True;假如不存在,则返回False。
Syntax语法
defined(name)
Parameter参数
Description描绘
name
Required.Specifiesthenameoftheconstanttocheck必要参数。指定常量对象的称号
Example事例
Theoutputofthecodeabovewillbe:
上述代码将输出下面的成果:
评论前必须登录!
注册