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.

27 lines
547 B

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