PHP intval() 和 (int) 转换的区别
来源:互联网 发布:windows下重启jenkins 编辑:程序博客网 时间:2024/05/29 08:30
1、intval & (int) 都不可以转换 Object。
2、转换效率 (int) > intval() > sprintf (intval 是PHP内置的方法,效率相对低)。
3、其他完全相同。
4、输入0123, 0x123 (int)函数也会按八进制和十六进制转换。
测试代码:
$n="19.99";$example = array( 19, '19', 19.99, '19.99','', 'abc123','123abc', 0x20, '0x20', array('19.99'), '+41', '-41', '10000000000000000000000000000000', (float)1999, null, $n*100, strval($n*100), 'j18ugj9hu0gj5hg',0123);foreach ($example as $key => $value){ echo 'The Transform Value Is: ' . gettype($value) . ' ' . json_encode($value) . "<br>"; echo "intval is :" , intval($value) . "<br>"; echo "(int) is :" , (int)($value) . "<br>"; echo "--------------------------------" . "<br>";}
运行结果:
The Transform Value Is: integer 19
intval is :19
(int) is :19
--------------------------------
The Transform Value Is: string "19"
intval is :19
(int) is :19
--------------------------------
The Transform Value Is: double 19.99
intval is :19
(int) is :19
--------------------------------
The Transform Value Is: string "19.99"
intval is :19
(int) is :19
--------------------------------
The Transform Value Is: string ""
intval is :0
(int) is :0
--------------------------------
The Transform Value Is: string "abc123"
intval is :0
(int) is :0
--------------------------------
The Transform Value Is: string "123abc"
intval is :123
(int) is :123
--------------------------------
The Transform Value Is: integer 32
intval is :32
(int) is :32
--------------------------------
The Transform Value Is: string "0x20"
intval is :0
(int) is :0
--------------------------------
The Transform Value Is: array ["19.99"]
intval is :1
(int) is :1
--------------------------------
The Transform Value Is: string "+41"
intval is :41
(int) is :41
--------------------------------
The Transform Value Is: string "-41"
intval is :-41
(int) is :-41
--------------------------------
The Transform Value Is: string "10000000000000000000000000000000"
intval is :2147483647
(int) is :2147483647
--------------------------------
The Transform Value Is: double 1999
intval is :1999
(int) is :1999
--------------------------------
The Transform Value Is: NULL null
intval is :0
(int) is :0
--------------------------------
The Transform Value Is: double 1999
intval is :1998
(int) is :1998
--------------------------------
The Transform Value Is: string "1999"
intval is :1999
(int) is :1999
--------------------------------
The Transform Value Is: string "j18ugj9hu0gj5hg"
intval is :0
(int) is :0
--------------------------------
The Transform Value Is: integer 83
intval is :83
(int) is :83
--------------------------------
- PHP intval() 和 (int) 转换的区别
- php下intval()和(int)转换使用与区别
- php下intval()和(int)转换使用与区别
- php下intval()和(int)转换使用与区别
- php下intval()和(int)转换使用与区别
- php下intval()和(int)转换使用与区别
- php中intval()的int转换剖析
- PHP中(int)与intval()的区别
- php intval和floatcal的区别
- PHP中intval()等int转换时的意外异常情况解析
- intval()和int()
- php数据入库前清理 注意php intval与mysql int 类型区别
- 刨根问底儿 -- intVal($str) 跟 (int) $str 的运算结果有什么区别
- intval PHP
- php取整函数ceil,floor,round,intval函数的区别
- php取整函数ceil,floor,round,intval函数的区别
- php取整函数ceil,floor,round,intval函数的区别
- PHP取整函数 ceil,floor,round,intval的区别详细解析
- 深入浅出ES6(四):模板字符串
- GitHub上README.md教程
- 3D全景制作VR全景技术讲解-全景智慧城市
- Java之不设置中间变量temp完成交换两个数
- centos7 yum安装配置redis
- PHP intval() 和 (int) 转换的区别
- 3槽Thunderbolt(雷电)PCIe扩展坞 EB3T
- myBatis返回integer值
- mac 启用tab自动补全
- C# 密码加密解密操作相关类
- ECC加密算法
- iOS的initWithFrame、initWithCoder、awakeFromNib
- 算法--二分查找
- 部署Tomcat的方法