2

Why the following code displays 2.5 instead of 3:

$a = 012;
echo $a / 4;
Julian Moreno
  • 1,084
  • 3
  • 15
  • 30

2 Answers2

2

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

WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
1

Starting a number with 0 like that means octal (base 8). So octal 12 = decimal 10.

Chris Rowles
  • 110
  • 1
  • 9