-2

I have a number 00101 when I print out this number (or using it for my purpose) I got 65, I've tried intval() but it also returns 65. Can anyone explain to me why? And what is the easiest way to get 00101, or 101?

Luu Hoang Bac
  • 433
  • 6
  • 17

2 Answers2

0

I would say you are using an invalid type of number, there is bits type (see the list of types in https://www.php.net/manual/en/langref.php)

if you run the following

$a = array(10101, 11100, 11010, 00101); var_dump($a);

you will see that PHP convert your number to int 65

so maybe you want to use strings?

lunarnet76
  • 666
  • 5
  • 8
0

You will get 101 from string '00101' when passing to intval function. However an integer number does not have start with leading 0; PHP does not get it as decimal number.

infomasud
  • 2,263
  • 1
  • 18
  • 12