📅  最后修改于: 2023-12-03 14:45:13.903000             🧑  作者: Mango
bccomp()
函数是PHP中的一种高精度比较函数,用于比较两个任意长度的数字字符串。该函数比较的结果相当于strcmp()函数。
int bccomp ( string $左操作数 , string $右操作数 [, int $小数位数 = 0 ] )
下面是一个使用bccomp()
函数进行数字字符串比较的示例:
<?php
$num1 = "1234567890123456789012345678901234567890";
$num2 = "1234567890123456789012345678901234567891";
$result = bccomp($num1, $num2);
if($result == 1) {
echo "num1 is greater than num2";
} elseif($result == -1) {
echo "num1 is less than num2";
} else {
echo "num1 is equal to num2";
}
?>
运行结果:
num1 is less than num2
bccomp()
函数可能会比较消耗资源,要谨慎使用。