欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP 类型转换函数intval

程序员文章站 2022-06-29 16:02:02
php代码 $id = intval($_get['id']); intval (php 4, php 5) intval — get the integer value...
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
?>