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简单命令代码集锦

删建:  引用 if(file_exists("file.htm"))// 检查是否存在此文件 if(file_exists("chat"))//检查是否存在此文件夹...

PHP创建文件,并向文件中写入数据,覆盖,追加的实现代码

创建文件我们用到函数 fopen ( string filename, string mode ) 参数filename为创建文件名 参数mode为以什么方式打开文件filename 其...

解析PHP中DIRECTORY_SEPARATOR,PATH_SEPARATOR两个常量的作用

一个是:DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR:路径分隔符,linux上就是‘/'    windows上是‘\'...

php使用curl实现ftp文件下载功能

本文实例为大家分享了php实现ftp文件下载功能,供大家参考,具体内容如下 不知道为什么用正常的ftp_get函数下载文件速度特别慢,但是用ftp的客户端下载很快,所以换了curl的下载...

php访问数组最后一个元素的函数end()用法

本文实例讲述了php访问数组最后一个元素的函数end()用法。分享给大家供大家参考。具体分析如下: end()函数在PHP中用于检索数组中的最后一个元素。end()函数需要一个数组作为其...