The gmp_cmp() function compares two GMP numbers.
Syntax
gmp_cmp(n1, n2)
Parameters
n1 − The first GMP number. It can be GMP object in PHP version 5.6 and later. Can also be numeric strings.
n2 − The second GMP number. It can be GMP object in PHP version 5.6 and later. Can also be numeric strings.
Return
The gmp_cmp() function returns:
- 1 if first number is greater,
- -1 if second number is greater,
- 0 if both the numbers are equal
Example
The following is an example −
<?php $n1 = "32"; $n2 = "32"; $cmpres = gmp_cmp($n1, $n2); echo $cmpres; ?>
Output
The following is the output −
0
Example
Let us see another example −
<?php $n1 = "25"; $n2 = "30"; $cmpres = gmp_cmp($n1, $n2); echo $cmpres; ?>
Output
The following is the output −
-1