PHP 类型转换函数intval

yipeiwu_com4年前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数学运算函数。分享给大家供大家参考,具体如下: 一、常用函数说明: Abs: 取得绝对值。 Acos: 取得反余弦值。 Asin: 取得反正弦值。 Atan: 取得反...

PHP文件操作实例总结

PHP文件操作实例总结

本文实例总结了PHP文件操作。分享给大家供大家参考,具体如下: 操作文件的常用方法: flie_put_contents(url,str); file_get_contents(url...

php获取图片信息的方法详解

本文实例讲述了php获取图片信息的方法。分享给大家供大家参考,具体如下: getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,...

php 特殊字符处理函数

但是我们可以用正则进行替换: 复制代码 代码如下:<?php function dhtmlspecialchars($string) { if(is_array($string))...

php常用字符串输出方法分析(echo,print,printf及sprintf) 原创

本文讲述了php常用字符串输出方法。分享给大家共大家参考,具体如下: 1. echo用法:可用echo 直接输出,也可以用echo()输出,无返回值 $string="<b&g...