PHP GMP gmp_cmp() 函数

PHP GMP gmp_cmp() 函数

PHP有一个内置函数叫做gmp_cmp(),用于比较两个GMP数。

语法

以下语法展示了使用GMP数进行清晰位操作的示例。

gmp_cmp(number1,number2);

参数

  • 该函数需要两个GMP数字参数,如$number1$number2
  • 在PHP版本5.6及更高版本中,给定的参数可以是GMP对象。
  • 我们也可以传递可以转换为数字的字符串值。

返回值

  • 如果”number”输出显示,则$number1大于$number2
  • 如果”0″输出显示,则$number1$number2相同。
  • 如果”-number”输出显示,则$number1小于$number2

示例

以下示例演示了使用GMP参数的”comparison”函数。

示例1: 以下示例展示了使用GMP函数进行基本比较操作。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_cmp() Function </h4>
<?php
value1 = gmp_cmp("85", "51");value2 = gmp_cmp("8","15" );
value3 = gmp_cmp("185","185" );
echo "The first value is greater than the second value: ".value1;
echo "<br/>";
echo "The second value is greater than the first value: ".value2;
echo "<br/>";
echo "The first value is equal to the second value: ".value3;
?>
</body>
</html>

输出:

下面的输出图像显示了使用GMP函数进行基本比较操作。

PHP GMP gmp_cmp() 函数

示例2: 下面的示例展示了使用GMP函数进行比较操作。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_cmp() Function </h4>
<?php
value1 = gmp_cmp("51", "-85");value2 = gmp_cmp("-8","15" );
value3 = gmp_cmp("-8","-8" );
echo "The first value is greater than the second value: ".value1;
echo "<br/>";
echo "The second value is greater than the first value: ".value2;
echo "<br/>";
echo "The first value is equal to the second value: ".value3;
?>
</body>
</html>

输出:

下面的输出图像显示了使用GMP函数进行的比较操作。

PHP GMP gmp_cmp() 函数

示例3: 下面的示例展示了使用”gmp_cmp()”运算符对两个值进行比较。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_cmp() Function </h4>
<?php
number1 = "510";number2 = "205";
number3 = "700";value1 = gmp_cmp(number1,number1);
value2 = gmp_cmp(number1,number2);value3 = gmp_cmp(number2,number3 );
echo " The comparison of the GMP two numbers: ".value1;
echo "<br/>";
echo "The comparison of the GMP two numbers: ".value2;
echo "<br/>";
echo "The comparison of the GMP two numbers: ".$value3;
?>
</body>
</html>

输出:

以下输出显示使用GMP函数进行的比较值。

PHP GMP gmp_cmp() 函数

示例4: 下面的示例展示了使用”gmp_cmp()”函数操作两个值的过程。该函数使用变量,以及其他GMP函数和“gmp_abs”函数。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_cmp() Function </h4>
<?php
number1 = "510";number2 = "-205";
value1 = gmp_cmp(number1, number2);
echo "The comparison value of two numbers: ".value1;
echo "<br/>";
value2 = gmp_abs(number2);
echo "<br/>";
value3 = gmp_cmp(number1,value2 );
echo "The comparison of the GMP two numbers: ".value3;
?>
</body>
</html>

输出:

以下输出显示了“AND”比较值。

PHP GMP gmp_cmp() 函数

示例5: 下面的示例演示了使用”gmp_init”函数的”gmp_cmp”函数。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_cmp() Function </h4>
<?php
value1 = gmp_init("534");value2 = gmp_init("314");
value3 = gmp_cmp(value1,value2 );value4 = gmp_cmp(value2,value1 );
echo "The comparison of the GMP two numbers: ".value3;
echo "<br/>";
echo "The comparison of the GMP two numbers: ".value4;
?>
</body>
</html>

输出:

以下输出显示比较值。

PHP GMP gmp_cmp() 函数

结论

“gmp_cmp()”函数用于使用单个操作比较两个参数。这是一种使用数值GMP参数进行比较的操作。

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程