PHP 类型转换函数intval

yipeiwu_com6年前PHP代码库
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
?>

相关文章

CURL的学习和应用(附多线程实现)

CURL的学习和应用(附多线程实现)

curl安装:windows下面的安装:修改php.ini文件的设置,找到php_curl.dll//取消下在的注释extension=php_curl.dll linux下面安装:复制...

PHP获取数组长度或某个值出现次数的方法

本文实例讲述了PHP获取数组长度或某个值出现次数的方法。分享给大家供大家参考。具体分析如下: count():对数组中的元素个数进行统计; 例如: $arr = Array('0',...

PHP中大括号'{}'用法实例总结

本文实例讲述了PHP中大括号'{}'用法。分享给大家供大家参考,具体如下: 在PHP中,大括号“{}”可以起到如下作用: 1、将多个独立语句合并为一个复合语句,例如 if ... els...

访问编码后的中文URL返回404错误的解决方法

访问编码后的中文URL返回404错误的解决方法

昨天做一个项目,其中有一个需求是每一张图片对应一小段文字对图片的说明,普通的做法是新建一个表然后把图片名与说明文字都记录到数据库内。仔细考虑后感觉这个应用不要数据库也能完成,我实现的方案...

利用php绘制饼状图的实现代码

drawPieImg()函数包含8个参数,$title为饼状图的标题;$dataArr为需要显示的数据数组;$labelArr为对应数据的标签分类数组;$colorArr为对应数据的绘图...