2

Why the following code displays 2.5 instead of 3:

$a = 012;
echo $a / 4;
Julian Moreno
  • 1,014
  • 3
  • 15
  • 29

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,267
  • 4
  • 30
  • 35
1

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

Chris Rowles
  • 88
  • 2
  • 8