前导零的结果为2.5而不是3.为什么? [重复]
问题描述:
This question already has an answer here:
Why the following code displays 2.5 instead of 3:
$a = 012;
echo $a / 4;
</div>
此问题已经存在 这里有一个答案: p>
-
数字具有前导零[重复]的奇怪行为
1 回答
span>
li>
ul>
div>
为什么以下代码显示 2.5 而不是 3 strong>: p>
$ a = 012; echo $ a / 4; code> pre> div>
答
Your variable is being interpreted as an octal. Per the docs:
To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x. To use binary notation precede the number with 0b.
Read more: http://php.net/manual/en/language.types.integer.php
答
Starting a number with 0 like that means octal (base 8). So octal 12 = decimal 10.