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中echo,print_r与var_dump区别分析

本文较为详细的分析了PHP中echo,print_r与var_dump区别。分享给大家供大家参考。具体分析如下: 三者都是具有输出功能的php语句,但print_r(expression...

PHP中Static(静态)关键字功能与用法实例分析

本文实例讲述了PHP中Static(静态)关键字功能与用法。分享给大家供大家参考,具体如下: 1、什么是static? static 是C++中很常用的修饰符,它被用来控制变量的...

php日期操作技巧小结

本文实例总结了php日期操作技巧。分享给大家供大家参考,具体如下: 1、php将表单里面获取的日期格式转换成统一的格式 2015-9-9 都统一转换成 2015-09-09 这样在数据库...

php google或baidu分页代码

复制代码 代码如下:<?php /** 作者:潇湘博客 时间: 2009-11-26 php技术群: 37304662 使用方法: include_once'Pager.class...

利用PHP判断文件是否为图片的方法总结

前言 在网页设计中,如果需要图片,我们通常拿到的是一个图片的文件名。仅仅通过文件名是无法判断该文件是否是一个图片文件的。或许有的人以为通过后缀名就可以判断,别忘了文件的后缀名是可以随便改...