PHP:为什么对此加法的答案是20,而不是22? [英] PHP: Why is the answer to this addition 20 and not 22?
本文介绍了PHP:为什么对此加法的答案是20,而不是22?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么输出到这个20,而不是22?好像您要添加10 + 0xA(十六进制中为10)+ 2.
Why is the output to this 20, and not 22? Seeing as you're adding 10 + 0xA(which is 10 in HEX) + 2.
$a = 010;
$b = 0xA;
$c = 2;
print $a + $b + $c;
Output: 20.
推荐答案
是正确的!
(因为第一个数字是octal
,所以如果希望将其解释为小数,则必须删除第一个0)
硒:
(Because the first number is octal
so if you want it to be interpreted as a decimal you have to remove the first 0)
Se:
$a = 010; //Octal -> 8
$b = 0xA; //Hex -> 10
$c = 2; //Dec -> 2
print $a + $b + $c; //20
输出:
20
这篇关于PHP:为什么对此加法的答案是20,而不是22?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文