Zero left inside integer variable

Asked

Viewed 498 times

1

Good afternoon guys, you hit the following doubt:

When I define within an integer variable the zero the left it returns me in echo a number nothing to see, I wonder why:

Follows exemplification:

 <?php
 echo $inteiro = 015;
//me retorna o seguinte valor: 13 gostaria de saber o pq?
 ?> 

1 answer

6


Because the 015 is the octagonal representation of the 13th decimal.

copied from the manual

<?php
$a = 1234; // decimal number
$a = -123; // a negative number
$a = 0123; // octal number (equivalent to 83 decimal)
$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)
$a = 0b11111111; // binary number (equivalent to 255 decimal)
?>
  • perfect answer

  • Thank you for the reply Manuel

  • Funny that even forcing the guy: $int = (int) 015; PHP still identifies the result as octagonal and changes the value of the variable.

  • @Kazzkiq independent of notation it remains an integer. Notation is just a different way of writing a number or a character. Barely comparing is like writing in Portuguese or English, the number remains the same.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.