Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

comparison - Interview question: In php, is 123==0123?

I have answered it is false. then he asked why? i couldn't answer. Can anyone make the answer? I am very interested to learn it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This code:

var_dump(123);
var_dump(0123);

will get you:

int 123
int 83

This is because 0123 is octal notation (because of the 0 at the beginning), while 123 is decimal.


For more information, you can take a look at the Integer section of the manual.


An even trickier question would have been to ask about 79 and 079, for instance :

var_dump(79);
var_dump(079);

will get you :

int 79
int 7

(9 is not a valid digit in octal ;-) )


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...