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
?>

相关文章

PHP实现数组和对象的相互转换操作示例

本文实例讲述了PHP实现数组和对象的相互转换操作。分享给大家供大家参考,具体如下: 关于php中想让对象以数组的形式访问,这时候就需要使用到get_object_vars()函数了。先来...

PHP判断一个字符串是否是回文字符串的方法

本文实例讲述了PHP判断一个字符串是否是回文字符串的方法。分享给大家供大家参考。具体实现方法如下: <?php function ishuiwen($str){...

PHP数据库表操作的封装类及用法实例详解

本文实例讲述了PHP数据库表操作的封装类及用法。分享给大家供大家参考,具体如下: 数据库表结构: CREATE TABLE `test_user` ( `id` int(11) NO...

PHP大转盘中奖概率算法实例

本文实例讲述了PHP大转盘中奖概率算法的实现方法,分享给大家供大家参考。具体如下: 大转盘是最近很多线上网动中一个比较有意思的东西了,下面我们就来看看这个大转盘中奖概率算法与例子,希望对...

PHP中让curl支持sock5的代码实例

复制代码 代码如下: //最近需要用到curl测试代理是否可用,代理是sock5非http的 所以需要在curl中增加几句。    curl_setopt($ch...