找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1297|回复: 0
打印 上一主题 下一主题

探讨php define()函数及defined()函数使用详解

[复制链接]

2487

主题

2487

帖子

7391

积分

论坛元老

Rank: 8Rank: 8

积分
7391
跳转到指定楼层
楼主
发表于 2018-2-14 08:20:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            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)

[TR]
Parameter
参数
Description
描述[/TR]
[TR]
[TD]name[/TD]
[TD]Required. Specifies the name of the constant
必要参数。指定常量的名称[/TD][/TR]
[TR]
[TD]value[/TD]
[TD]Required. Specifies the value of the constant
必要参数。指定常量的值[/TD][/TR]
[TR]
[TD]case_insensitive[/TD]
[TD]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[/TD][/TR]
Example 1
案例1
Define a case-sensitive constant:
指定一个常量(区分大小写):
[U]复制代码[/U] 代码如下:
The output of the code above will be:
上述代码将输出下面的结果:
[U]复制代码[/U] 代码如下:
Hello you! How are you today?
Example 2
案例2
Define a case-insensitive constant:
指定一个常量(不区分大小写):
[U]复制代码[/U] 代码如下:
The output of the code above will be:
上述代码将输出下面的结果:
[U]复制代码[/U] 代码如下:
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
语法
[U]复制代码[/U] 代码如下:
defined(name)
[TR]
Parameter
参数
Description
描述[/TR]
[TR]
[TD]name[/TD]
[TD]Required. Specifies the name of the constant to check
必要参数。指定常量对象的名称[/TD][/TR]
Example
案例
[U]复制代码[/U] 代码如下:

The output of the code above will be:
上述代码将输出下面的结果:
1
            
            
您可能感兴趣的文章:
  • 深入php define()函数以及defined()函数的用法详解
  • 解析php中const与define的应用区别
  • 解析php中static,const与define的使用区别
  • php define的第二个参数使用方法
  • ThinkPHP模板判断输出Defined标签用法详解
  • php中define用法实例
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端