前导零的结果为2.5而不是3.为什么? [重复]

前导零的结果为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>

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.