加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 整数类型转换问题

发布时间:2020-12-13 18:02:52 所属栏目:PHP教程 来源:网络整理
导读:情况#1:我有以下代码输出正确的数字 ?php $integer = 10000000000; $array = array($integer); print_r($array[0]); //output = 1000000000? 情况#2:但是当我明确地将相同的数字类型转换为整数时,它会给出不同的输出 ?php $integer = (int)10000000000; $a
情况#1:我有以下代码输出正确的数字
<?php 
   $integer = 10000000000;
   $array = array($integer);
   print_r($array[0]); //output = 1000000000
?>

情况#2:但是当我明确地将相同的数字类型转换为整数时,它会给出不同的输出

<?php
    $integer = (int)10000000000;
    $array = array($integer);
    print_r($array[0]); //output = 1410065408
?>

情况#3:如果我将数字减去一个0并输入它,那么它返回正确的数字

<?php
   $integer = (int)1000000000;
   $array = array($integer);
   print_r($array[0]); //output = 1000000000
?>

为什么它没有在CASE#2中产生正确的输出?

您最有可能超过平台上int的最大值.

Official PHP Doc

The size of an integer is platform-dependent,although a maximum value
of about two billion is the usual value (that’s 32 bits signed). Integer size can be
determined using the constant PHP_INT_SIZE,and maximum value using
the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

对于32位平台:

整数可以从-2147483648到2147483647

对于64位平台:

整数可以是-9223372036854775808至9223372036854775807

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读