PHP 类型转换函数intval
作者:bea
PHP代码 $id = intval($_GET['id']); intval (PHP 4, PHP 5) intval — Get the integer value of a variable Description int intval ( mixed $var [, int $base= 10 ] ) Returns the integer value of var , using the specified base for the conversion (the
PHP代码 $id = intval($_GET['id']);
intval (PHP 4, PHP 5)
intval — Get the integer value of a variable
Description
int intval ( mixed $var [, int $base= 10 ] )
Returns the integer value of var , using the specified base for the conversion (the default is base 10).
Parameters
var The scalar value being converted to an integer
base The base for the conversion (default is base 10)
Return Values The integer value of var on success, or 0 on failure. Empty arrays and objects return 0, non-empty arrays and objects return 1.
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
Examples
代码如下:
<?php
echo intval(42); // 42
echo intval(4.2); // 4
echo intval('42'); // 42
echo intval('+42'); // 42
echo intval('-42'); // -42
echo intval(042); // 34
echo intval('042'); // 42
echo intval(1e10); // 1410065408
echo intval('1e10'); // 1
echo intval(0x1A); // 26
echo intval(42000000); // 42000000
echo intval(420000000000000000000); // 0
echo intval('420000000000000000000'); // 2147483647
echo intval(42, 8); // 42
echo intval('42', 8); // 34
?>
有用 | 无用
intval (PHP 4, PHP 5)
intval — Get the integer value of a variable
Description
int intval ( mixed $var [, int $base= 10 ] )
Returns the integer value of var , using the specified base for the conversion (the default is base 10).
Parameters
var The scalar value being converted to an integer
base The base for the conversion (default is base 10)
Return Values The integer value of var on success, or 0 on failure. Empty arrays and objects return 0, non-empty arrays and objects return 1.
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
Examples
代码如下:
<?php
echo intval(42); // 42
echo intval(4.2); // 4
echo intval('42'); // 42
echo intval('+42'); // 42
echo intval('-42'); // -42
echo intval(042); // 34
echo intval('042'); // 42
echo intval(1e10); // 1410065408
echo intval('1e10'); // 1
echo intval(0x1A); // 26
echo intval(42000000); // 42000000
echo intval(420000000000000000000); // 0
echo intval('420000000000000000000'); // 2147483647
echo intval(42, 8); // 42
echo intval('42', 8); // 34
?>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- PHP HTML代码串 截取实现代码
- PHP 网页过期时间的控制代码
- PHP 超链接 抓取实现代码
- PHP 文件上传功能实现代码
- PHP n个不重复的随机数生成代码
- PHP 七大优势分析
- php 404错误页面实现代码
- PHP 多进程 解决难题
- PHP 数据库 常见问题小结
- PHP 高级课程笔记 面向对象
- mysql 性能的检查和优化方法
- php fckeditor 调用的函数
- 学习discuz php 引入文件的方法DISCUZ_ROOT
- php 分页函数multi() discuz
- 一个php Mysql类 可以参考学习熟悉下
- php 将bmp图片转为jpg等其他任意格式的图片
- ie6 动态缩略图不显示的原因
- PHP COOKIE设置为浏览器进程
- php 图像函数大举例(非原创)