Question
If I assign and print a value like this:
$a = 012;
print $a;
I get back a value of '10', why?
Answer
This is because prefixing a number with a 0 in PHP forces the number to be interpreted as an octal value. However, it is stored internally as an integer value so when it is printed we get the integer value back. To get back the original octal value you could do something like this:
print base_convert($a, 10, 8);
Or even this:
print decoct($a);
Or even this:
print sprintf("%o", $a);
Comments
in this case if you add first zero, php will interpreted the variable as octal number and convert this value to decimal number (?) ;p
The title of the post gave this away, otherwise you might have got me with this one :)