define() 函数用于定义一个常量

常量类似变量,不同住处在于:

  • 常量在设定之后,它的值无法更改
  • 常量名不需要开头的美元符号$
  • 作用域不影响对常量的访问
  • 常量值只能是字符串或者数字

语法:define(name,value,case_insensitive)

name 必需,常量的名称
value 必需,设置常量的值
case_insensitive 可选,规定常量的名称是否对大小写敏感。

若设置为 true,则对大小写不敏感。默认是 false(大小写敏感

比如:

<?php

  define("myWebsite","http://wuhaidong.me",true);

  echo constant("mywebsite");    // constant()返回一个常量的值

?>

输出: http://wuhaidong.me

 

defined()函数是检查某常量是否存在,如果存在,则返回ture,否则,返回false

比如:

<?php

  define("myWebsite","http://wuhaidong.me");

  echo defined("myWebsite");
?>

输出:1

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
猜你喜欢
  • 2022-12-23
  • 2021-10-07
  • 2022-01-02
  • 2022-02-07
  • 2021-10-19
  • 2021-08-27
  • 2022-12-23
相关资源
相似解决方案