Blogger Information
Blog 4
fans 0
comment 0
visits 2005
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php变量与常量
苦咖啡
Original
487 people have browsed it

变量与常量

  • 变量八种类型:
    • 布尔型boolean,整型int,字符串string,浮点型(小数点)
    • 数组,对象
    • null,resource
  • 变量的转换:
    • 强制类型的转换(临时)
      • (int)$name;强制转换为整型
      • (string)$username;强制转换为字符串型
      • (boolean)$one;转换为布尔型
      • (array)$arr;转换为数组
      • (float)$num;转换为浮点型
      • (object)$object;转换为对象
      • (unset)$uid;转换为null。
    • 系统自动的转换
      • 通过加减运算,从而使其自动转换为整型,
    • 永久转换(settype()函数)
      • settype($val,$type)
        $type:有integer,string,boolean,float,array,null,object,
  • 常量的定义:
    • define(“WZM”,”姓名的缩写”);
      echo WZM;
    • const WZM =”姓名的缩写”;
      echo WZM;
      1. <?php
      2. // 常量的值不能更改;变量的值可以更改。
      3. define("WZM","姓名的缩写");
      4. $wzm1 = "咖啡";
      5. echo "更改之前:".WZM;
      6. echo "<br/>";
      7. echo "更改之前:".$wzm1;
      8. echo "<hr/>";
      9. define("WZM","王之满");//更改了会报错,
      10. $wzm1 = "咖啡王之满";
      11. echo "更改之后:".WZM;
      12. echo "<br/>";
      13. echo "更改之后:".$wzm1;
      14. // 常量,不管是否是在函数体内或函数体外,作用域是一样的。变量,作用域不一样
      15. echo "<hr/>";
      16. function add(){
      17. echo "在函数体内输出常量:".WZM;
      18. echo "<br/>";
      19. $wzm1 = "函数体内";
      20. echo "在函数体内输出变量:".$wzm1;
      21. }
      22. add();
      23. echo "<hr/>";
      24. echo "在函数体<span style='color:red'>外</span>输出变量:".$wzm1;
      25. ?>
Correcting teacher:PHPzPHPz

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