You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
585 B

3 years ago
3 years ago
  1. <?php
  2. //定义常量
  3. define('a','1');
  4. const b=2;
  5. //调用常量,不需要$号
  6. echo a.'<br>';
  7. echo b.'<br>';
  8. //b=3; //b是常量,不能再修改
  9. //echo b;
  10. //获取常量
  11. $b='b';
  12. echo constant($b).'<br>';
  13. //判断常量是否存在
  14. const c=3;
  15. $d=4;
  16. var_dump(defined('c')); //常量c存在,返回true
  17. echo '<br>';
  18. var_dump(defined('d')); //d不是常量,返回false
  19. echo '<br>';
  20. //魔术常量
  21. echo "当前文件路径".__FILE__;
  22. /*
  23. 感悟:php常量像C语言里的宏
  24. */
  25. ?>