小白教程
所有教程
关于
Search
172.70.130.161
172.70.130.161
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Func misc define”的源代码
本页内容
上一节:
Func_misc_constant
下一节:
Func_misc_defined
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:define()}}[[Category:PHP 杂项函数参考手册|4]] = PHP define() 函数 = [[:Category:PHP 杂项函数参考手册]] 定义一个大小写敏感的常量: <sample title="" desc="" lang="php" hererun="1"> <?php define("GREETING","Hello you! How are you today?"); echo constant("GREETING"); ?> </sample> == 定义和用法 == define() 函数定义一个常量。 常量类似变量,不同之处在于: * 在设定以后,常量的值无法更改 * 常量名不需要开头的美元符号($) * 作用域不影响对常量的访问 * 常量值只能是字符串和数字 == 语法 == define(name,value,case_insensitive) {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | name | 必需。规定常量的名称。 |- | value | 必需。规定常量的值。PHP7 支持数组,实例如下: <sample title="" desc="" lang="php" hererun="1"> <?php // PHP7+ 支持 define('ANIMALS', [ 'dog', 'cat', 'bird' ]); echo ANIMALS[1]; // 输出 "cat" ?> </sample> |- | case_insensitive | 可选。规定常量的名称是否对大小写敏感。可能值: * TRUE - 大小写不敏感 * FALSE - 默认。大小写敏感 |} == 技术细节 == {| class="table table-striped table-hover" | 返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |- | PHP 版本: | 4+ |} == 更多实例 == 定义一个大小写不敏感的常量: <sample title="" desc="" lang="php" hererun="1"> <?php define("GREETING","Hello you! How are you today?",TRUE); echo constant("greeting"); ?> </sample> [[:Category:PHP 杂项函数参考手册]]
返回至“
Func misc define
”。
上一节:
Func_misc_constant
下一节:
Func_misc_defined