Why the following code displays 2.5 instead of 3:
$a = 012;
echo $a / 4;
Why the following code displays 2.5 instead of 3:
$a = 012;
echo $a / 4;
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.