开发者

why there is a difference between below given output?

开发者 https://www.devze.com 2023-02-09 04:26 出处:网络
$y = 07; echo \'Y: \'.$y; // result is 7 $y = 08; echo \'Y: \'.$y; // result is 0 开发者_JAVA百科 view demo
$y = 07;
echo 'Y: '.$y; // result is 7
$y = 08;
echo 'Y: '.$y; // result is 0
开发者_JAVA百科

view demo

:EDIT:

One more similar to that

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

I can not figure it out how its ans is 16? Can any one help?


Part 1

The rules for parsing are explained in the Integers Documentation.

In PHP a number starting with a 0 is a assumed to be in Octal. Because 08 in Octal isn't valid you are getting 0.

Part 2

The same issue is in play, 013 in Octal is 11 in Decimal and 11 + 5 = 16


In php integer variable is taken Octal.

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

show This link useful for you.i think.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号