donglu5728 2017-06-08 03:02
浏览 24

“数组项”和常量“定义”仅显示0而不是整数

I declared an array item "0859" but when I display the array item, it shows only the 0 and not the whole number "0859".

In constant define I set the value to "01238" the result is the same with my array, it shows only the value 0 and not the whole number 01238. I would like to know further about the reason why array item and define that starts with 0 in there item and values shows only the 0 and not the whole number

Array

<?php
  $num = [0859];
  echo $num;

  output: 0

  Why not the the output is "0859"
?>

Constant Define

<?php

  define(myNum, 01238);
  echo myNum;

  output: 0

  Why not the the output is "01238"

?>

I'm using Wamp PHP version 5.5.12

Please enlighten me why I get the output only 0 and not the whole number

  • 写回答

2条回答 默认 最新

  • dongou5100 2017-06-08 03:15
    关注

    If you're running PHP7 you should probably take a look at this answer.

    As said in the linked answer:

    This comes from the changes made to how integers, specifically octals, are handled in PHP7 (as oppsoed to PHP5).

    Invalid octal literals

    Previously, octal literals that contained invalid numbers were silently truncated (0128 was taken as 012). Now, an invalid octal literal will cause a parse error.

    Either use them as strings, or actual integers

    $a = array(1, 8, 9, 12); // Integers

    $a = array("00001", "00008", "00009", "00012"); // Strings

    You can find more info on Integers/Octals here: http://php.net/manual/en/language.types.integer.php

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探