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服务端环境搭建的图文教程(分享)

PHP服务端环境搭建的图文教程(分享)

一、PHP服务端环境搭建 1.php 服务端环境 安装套件 xampp(apach+mysql+php解释器) F:\MyDoc文件(重要)\DL_学习\download重要资源\apa...

flash用php连接数据库的代码

php代码:复制代码 代码如下: /* /flashservices/services/Catalog.php */ class Catalog {     &nbs...

PHP实现C#山寨ArrayList的方法

本文实例讲述了PHP实现C#山寨ArrayList的方法。分享给大家供大家参考。具体如下: class ArrayList { public $length; public $n...

php求今天、昨天、明天时间戳的简单实现方法

本文实例讲述了php求今天、昨天、明天时间戳的简单实现方法。分享给大家供大家参考,具体如下: echo strtotime('now'),'<br>';//现在 echo...

php用户登录之cookie信息安全分析

本文实例讲述了php用户登录之cookie信息安全。分享给大家供大家参考,具体如下: 大家都知道用户登陆后,用户信息一般会选择保存在cookie里面,因为cookie是保存客户端,并且c...