我无法在PHP变量中存储0123 [重复]

Possible Duplicate:
Interview question: In php, is 123==0123?

I am newbie in PHP. I am trying to store 0123 in a PHP variable while learning PHP but it displays 83 instead of 0123 when I echo the variable. Can anyone give me exact technical reason of that.

Thanks in Advance, Dhaval

You are probably doing something like this

$var = 0123;

This is an integer and not a string. Sidenote: "0123" is not a number, because no number has a leading 0 except abs($var)<1 or $var == 0. But the leading 0 has a special meaning when used with integers: It is treated as a base-8-integer, which is then converted into base-10

               0123_8 = 83_10
1*8^2 + 2*8^1 + 3*8^0 = 8*10^1 + 3*10^0

Because you're probably trying to store is as an integer when you should be storing it as a string.

// Incorrect
$var = 0123 // octal number (equivalent to 83 decimal)

// Correct
$var = '0123'

If you are doing it like this:

$a = 0123;

Then you are using octal numbers where indeed 0123 = 83.