PHP GMP gmp_cmp() Function

PHP has a built-in function called gmp_cmp() that is used to compare two GMP numbers.

Syntax

The following syntax shows a clear bit function using GMP numbers.

Parameter

  • The two GMP numbers such as $number1 and $number2 are required parameters for this function.
  • In PHP versions 5.6 and later, the given parameters can be a GMP object.
  • We can also pass numeric string values that can be converted into numbers.

Return Value

  • If the "number" output displays then $number1 is greater than $number2,
  • If the "0" output displays then $number1 is the same as $number2,
  • If the "-number" output displays then $number1 is less than $number2.

Examples

The following examples show the "comparison" function using the GMP parameters.

Example1: The following example shows the basic comparison operation using the GMP function.

Output:

The following output image shows the basic comparison operation using the GMP function.

PHP GMP gmp_cmp() Function

Example2: The following example shows the comparison operation using the GMP function.

Output:

The following output image shows the comparison operation using the GMP function.

PHP GMP gmp_cmp() Function

Example3: the following example shows a comparison of the two values using the "gmp_cmp()" operator.

Output:

The following output shows the comparison values using the GMP function.

PHP GMP gmp_cmp() Function

Example4: the following example shows the operation of the two values using the "gmp_cmp()" function. This function uses variable, other GMP functions with the "gmp_abs" function.

Output:

The following output shows the "AND" comparison value.

PHP GMP gmp_cmp() Function

Example5: the following example shows the "gmp_cmp" with the "gmp_init" function.

Output:

The following output shows the comparison value.

PHP GMP gmp_cmp() Function

Conclusion

The "gmp_cmp()" function uses to compare two parameters with a single operation. It is a comparison operation with numerical GMP parameters.






Latest Courses