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)

What does a leading zero do for a php int?

echo(073032097109032116104101032118101114121032109111100101108032111102032097032109111100101114110032109097106111114032103101110101114097108046);

Essentially, a very large number. Now, why does it output 241872? I know PHP has float handlers. When I remove the leading zero, it functions as expected. What is that leading zero signifying?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

If you use a leading zero, the number is interpreted by PHP as an octal number. Thus, a 9 is not a valid part of the number and the parser stops there:

  0730320 (base 8)
=  7 * 8^5 + 3 * 8^4 + 3 * 8^2 + 2 * 8^1
=  7 * 32768 + 3 * 4096 + 3 * 64 + 2 * 8 (base 10)
=  241872 (base 10)

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

...