I don't know how to google this one out so I an asking it here. Why does it happen that when I declare a variable $something = 0759
that it turns into 61. I know the answer must be very simple so please forgive my sillyness.
It is an Integer literal, you declare a octal number with a leading zero.
$something = 0759; // octal
The octal numeral system is a base-8 number system. You can only use Numbers between 0-7 (other numbers are discarded).
$a = 0759;
$b = 075;
var_dump($a==$b);
// bool(true)
http://www.php.net/manual/en/language.types.integer.php
You could skip the zeros with ltrim.
$a = ltrim("0759", 0);
echo $a; // 759
// and reformat as suggested with str_pad or printf
echo str_pad($a, 4, "0", STR_PAD_LEFT);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With