Blogger Information
Blog 21
fans 0
comment 1
visits 19138
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
细说PHP的变量
XFY_肆意De...
Original
583 people have browsed it
变量的数据类型;
  1. 基本类型,一般分为,整型int,浮点型float,字符型string,布尔型bool.
  2. 符合类型:数组与对象 array or object
  3. 特殊类型:null 与资源 resource
变亮数据类型的获取;

使用gettype()函数来获取

  1. $user = '张三';
  2. echo gettype($user);
  3. //输出:string(字符型);
  4. $pai = 3.1415126;
  5. echo gettype($pai);
  6. //输出:double (双精度浮点数)
  7. $isMobile=true;
  8. echo gettype($isMobile);
  9. //输出 boolean (布尔型)
  10. $obj= new stdClass;
  11. echo gettype($obj);
  12. //输出 object (对象-复合类型)
变量类型转;
  1. 自动转换;是由系统自己转换,不需要我们关心
  1. $a=true;
  2. $b=34;
  3. $c='20';
  4. echo $a+$b+$c;
  5. //$a:系统自动将布尔类型的true转换为整型1;
  6. //$b: 数字类型不转换34;
  7. //$c: 系统自动将字符型的‘20’转换为整型20;
  8. //输出:$a+$b+$c=55
  1. 强制转换:
  1. $a=true;
  2. $b=34;
  3. $c='PHP中文网';
  4. echo (int)$a+$b+(int)$c;
  5. //$a:强制将布尔类型的true转换为整型1;
  6. //$b: 数字类型不转换34;
  7. //$c: 强制将字符型的‘PHP中文网’转换为整型(字符串与null在算术运算中均为0);
  8. //输出:$a+$b+$c=35
  1. 另外PHP提供了一个涵数用来永久转换自己需要的数据类型:

settyppe($data,$type)

  1. $a=true;
  2. settype($a,'int');
  3. echo gettype($a);
  4. //输出:integer
  1. 可变变量:
  1. $user = 'userName';
  2. // 动态创建可变变量
  3. $$user = 'peter';
  4. echo $user; //输出 userName
  5. echo '<hr>';
  6. echo $userName; //输出 peter ($userName未定义,是通过$user动态创建)

总结:
了解了变量的数据类型及如何获取变量;
了解了变量的检测与删除及转换;
了解了可变变量;
备注知识点:

Correcting teacher:GuanhuiGuanhui

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