前导零正在改变php中的结果[重复]

问题描述:

This question already has an answer here:

Let us assume In PHP

$i = 016;
echo $i / 2;

The output is returning 7.! why..?

</div>

此问题已经存在 这里有一个答案: p>

  • 一个前导零为php int做什么? 4个答案 span> li> ul> div>

    让我们假设在PHP中 p>

      $ i = 016; 
    echo $ i / 2; 
      code>  pre> 
     
     

    输出返回 7 code >! 为什么......? p> div>

Appending 0 to the front of a number in PHP is making it octal.

16 in octal is equivalent to 14 in decimal.

So , 14/2 = 7 is the answer.

The leading 0 will cause 016 to be interpreted as written in base 8, thus in base 10 it will actually be 14. So 14/2 = 7