我需要在PHP中比较两个整数。我有这个例子:
$a=00713132161838;
$b=713132161838;
我怎样才能使这种比较正确呢?我需要从$ a中删除前导零。
我使用了number_format函数:
echo number_format($a,0,"","");
120370289
为什么这个??
在php中以0开头的数字是八进制数字,它打印的120370289
是的十进制等效项00713132161838
。因此在php中有两种比较,
(`00713132161838`==713132161838) // return true
(`00713132161838`===713132161838) // return false and strict comparison
(00713132161838==713132161838)
// this will never give you true value because 007.....8 is the octal, number first converted to decimal and comparison will be there
因此,您可以使用单引号/双引号将数字包装起来,然后通过使用intval
以获得更多信息将其转换为十进制整数值,您可能需要阅读php中的intval函数
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句