PHP 类型转换函数intval

yipeiwu_com5年前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
?>

相关文章

linux系统上支持php的 iconv()函数的方法

1、下载libiconv函数库http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.9.2.tar.gz; 2、解压缩tar -zxvf libi...

PHP进阶学习之Geo的地图定位算法详解

PHP进阶学习之Geo的地图定位算法详解

本文实例讲述了PHP进阶学习之Geo的地图定位算法。分享给大家供大家参考,具体如下: 前言 日常开发中我们经常需要查找某个物体的定位,或者查找附近的范围等,我们自然而然会想到的方法就是...

浅析php数据类型转换

PHP 在变量定义中不需要(或不支持)明确的类型定义;变量类型是根据使用该变量的上下文所决定的。也就是说,如果把一个字符串值赋给变量 var,var 就成了一个字符串。如果又把一个整型值...

PHP 加密解密内部算法

将它们打包成一个文件就叫fun.php吧 复制代码 代码如下: <?php function passport_encrypt($txt, $key) { srand((doubl...

PHP用continue跳过本次循环中剩余代码的注意点

前言 大家都知道,在PHP中continue 在循环结构用用来跳过本次循环中剩余的代码并在条件求值为真时开始执行下一次循环。一定要注意的是,用了continue要用“;”来隔开其他的代码...