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
?>

相关文章

PHP快速排序算法实现的原理及代码详解

PHP快速排序算法实现的原理及代码详解

算法原理 下列动图来自五分钟学算法,演示了快速排序算法的原理和步骤。 步骤: 从数组中选个基准值 将数组中大于基准值的放同一边、小于基准值的放另一边,基准值位于中间位置 递归的对分...

php Rename 更改文件、文件夹名称

php Rename 更改文件、文件夹名称

命令格式为: bool rename ( string oldname, string newname [, resource context] )   下面演示rename的具体应用:...

php mb_substr()函数截取中文字符串应用示例

substr()函数用来截取字符串,但是对于中文字符会出现问题,而mb_substr()和mb_strcut这两个函数可以,用法与substr()相似,只是在函数最后要加入多一个参数,以...

浅谈PHP的exec()函数无返回值排查方法(必看)

在安全imagemagic时 需要用到 exec很多服务器上安装失败 exec()执行外部命令失败,但没有任何错误信息。 exec执行某命令在命令行下没有问题,但是在php中就出错。这个...

php正则删除img标签的方法示例 原创

本文实例讲述了php正则删除img标签的方法。分享给大家供大家参考,具体如下: 一、问题 正则抓取过程中需要删除正文中的img标签,如: <div>欢迎访问【宜配屋www...