Why is there a difference between the data below?

$y = 07; echo 'Y: '.$y; // result is 7 $y = 08; echo 'Y: '.$y; // result is 0 

watch demo

: EDIT:

Another similar to that

 $y = 013; echo $y + 5; //this result in 16 

I can not understand how its ans 16? Can anyone help?

+4
source share
2 answers

Part 1

Rules for parsing are explained in the Target Documentation .

In PHP, a number starting with 0 is assumed to be in Octal. Since 08 in Octal is not valid, you get 0.

Part 2

The same applies to the game, 013 in Octal - 11 in decimal and 11 + 5 = 16

+6
source

In the php integer variable, Octal is accepted.

http://www.ascii.cl/conversion.htm

show This link is useful to you. I think.

0
source

Source: https://habr.com/ru/post/1338978/


All Articles