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中ob_flush和flush的区别

ob_flush/flush在手册中的描述, 都是刷新输出缓冲区, 并且还需要配套使用, 所以会导致很多人迷惑… 其实, 他们俩的操作对象不同, 有些情况下, flush根本不做什么事情...

PHP高效获取远程图片尺寸和大小的实现方法

 PHP高效获取远程图片尺寸和大小的实现方法 在这里分享一下自己的心得,希望和大家一起分享技术,如果有什么不足,还请大家指正。写出这篇目的,就是希望大家一起成长,我也相信技术之...

js+php实现静态页面实时调用用户登陆状态的方法

本文实例讲述了js+php实现静态页面实时调用用户登陆状态的方法。分享给大家供大家参考。具体分析如下: 在程序开发中,经常会把页面做成html的静态形式,这样可以减轻服务器负载,但是也存...

浅谈PHP错误类型及屏蔽方法

程序只要在运行,就免不了会出现错误,错误很常见,比如Error,Notice,Warning等等。在PHP中,主要有以下3种错误类型。 1.注意(Notices) 这些都是比较小而且不严...

C# WinForm中实现快捷键自定义设置实例

C# WinForm中实现快捷键自定义设置实例

本文源码下载:http://xiazai.jb51.net/201501/tools/cs-key-setting.rar 项目开发过程中,需要实现类似有道词典的软件设置中的自定义快捷键...