Blogger Information
Blog 5
fans 0
comment 0
visits 2751
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0107作业常量练习
阿喜
Original
557 people have browsed it

0107作业常量双引号索引数组关联数组分支流程控制练习

1.常量的定义

  • 常量的定义,define(‘常量名’, ‘对应的常量值’);
  • const 常量名 = ‘应的常量值’;
  • 以上有两种定义的方法,const可以定义类常量。
  • define可以用于表达式,const只能用于字面量。
  • 举例说明一下
    1. //常量的定义,define('常量名', '对应的常量值');
    2. //常规推荐大写常量名
    3. define("NAME", "PHP中文网");
    4. echo NAME; // outputs "Hello world."
    5. echo '<br>';
    6. //常量的定义,define('常量名', '对应的常量值');
    7. define('WEB','www.php.cn');
    8. echo WEB;
    9. echo '<br>';
    10. //const 常量名 = '应的常量值';
    11. const USERNAME='中文网站';
    12. echo USERNAME;
    13. echo '<br>';
    14. //const 与define不同之处,const可以定义类常量。
    15. //例如下
    16. //定义一个类常规
    17. class test{
    18. const TEST_NAME='PE';
    19. }
    20. //类常规的输出写法:
    21. echo test::TEST_NAME.'<br>';
    22. //define()可以用做表达式为值 ,const 不能只能用做字面量
    23. //例:
    24. $email_name='qq.com';
    25. define('MYEMAIL','admin@'.$email_name);
    26. echo MYEMAIL;
  • 运行结果如图示
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:继续努力
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post