本文介绍了前面有0的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有函数
$ x = 012;
echo $ x / 3;
为什么结果是3.33333?
但如果我使用:
pre $ code $ x ='012';
然后是正确的。问题是这怎么解释?
解决方案
以0开头的数字被视为八进制数字:
$ x = 012; // $ x是10
原因是 $ x ='012';
的作用是因为PHP将它转换为整数而不将其视为八进制数字。
I have function
$x = 012;
echo $x / 3;
Why the result is 3.33333?
But if I use:
$x = '012';
Then is right. The question is how can this be explained?
解决方案
Numbers prefixed with 0 are treated as octal numbers:
$x = 012;//$x is 10
The reason that $x = '012';
works is because PHP converts that to an integer without treating it as an octal number.
这篇关于前面有0的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!