我需要比较PHP中的两个整数。我有这个例子:比较php中的两个整数
$a=00713132161838;
$b=713132161838;
我怎样才能得到这个比较是真的?我需要从$ a中删除前导零。
我用number_format功能:
echo number_format($a,0,"","");
120370289
为什么这样?
我需要比较PHP中的两个整数。我有这个例子:比较php中的两个整数
$a=00713132161838;
$b=713132161838;
我怎样才能得到这个比较是真的?我需要从$ a中删除前导零。
我用number_format功能:
echo number_format($a,0,"","");
120370289
为什么这样?
前导零到PHP中的数字是八进制数,并将其打印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
以获取更多信息,您可能需要阅读intval function in php
如果你有答案,你可以接受答案......? –
'$ a = 00713132161838;'当您声明整数值时出现零点意味着该值被视为八进制值,而不是小数[PHP文档](http://www.php.net/) manual/en/language.types.integer.php) –