Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Any one can explain to me? why it's returning 83?

<p>&lt;?php</p> <p>$k=0123;echo $k;</p> <p>?&gt;</p>

user-image
Question added by Kamatchi Panneer Selvam , Software Developer , Comtel General Trading LLC
Date Posted: 2014/10/13
Majid Hameed
by Majid Hameed , Senior Java Developer , Check24 Vergleichsportal GmbH

Yes anything that starts with0 is an octal integer.

If you don't want to store string and want to store number then following are2 options.

$k =0123.00;

OR if you want to stick with integer then you can do casting.

$k = (int)0123.00;

Yousef Adel Abdulaziz
by Yousef Adel Abdulaziz , Information Technology Specialist , Takamol Holding

Because it's assigning $k to the octal value of0123 which is83.

0123 =83 in octal

Instead, try to store0123 as a string e.g. $k = "0123";

Julfkar  Moh Umar
by Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited

This is OCTAL Number so this will be calculated as:

 

1*8^2+2*8^1+3*8^0 =

More Questions Like This