php函数intval,PHP 类型转换函数intval

不管什么类型 如果是数字,就返回数字,如果不是数字就返回0

在PHP中用$_GET['id']的时候就可以这样来一个转换...太好了

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

varThe scalar value being converted to an integerbaseThe 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

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

?>

posted on 2009-06-18 11:20 haix 阅读(2258) 评论(0)  编辑 收藏 引用 网摘 所属分类: PHP

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值