Search code examples
phpnumbersoctal

Weird output, when number starts with 0


1. script:

$num = "00445790";
echo $num;

returns:

00445790

2. script

$num = 00445790;
echo $num;

returns:

2351

Can somebody explain why I get 2351 on the second script?


Solution

  • Integers that start with zero are consider octal. Because octal integers only use numbers from 0 to 8 everything from the 9 on are ignored.

    So 00445790 becomes 004457 which is 2351 in decimal.