gmp_cmp ($num1, $num2)Parameters:this function accepts two GMP numbers $num1 and $num2 as required parameters, as shown in the above comparison syntax. These parameters can be GMP object in PHP 5.6 and later, or we are also allowed to pass in numeric strings so that we can convert those strings to numbers.Return value:function returns "1" if $num1 > $num2, "0" if $num1 is equal to $num2, "-1" if $num1 < $num2.Examples:
Input: gmp_cmp ("1234" , "1236") Output: -1 Input: gmp_cmp ("3569", "3569") Output: 0The following programs illustrate the gmp_cmp() function in PHP:Program 1:A program to compare two GMP numbers when transmitted as numeric strings.
php
// PHP program to compare two
// GMP numbers are passed as arguments
// lines as GMP numbers
$num1
=
" 12356 "
;
$num2
=
"12356"
;
// compares two numbers and
// results in & quot; 0 & quot; because both are equal
$res
= gmp_cmp (
$num1
,
$num2
);
echo
$res
;
?>
Output:0Program 2:A program to compare two GMP numbers when passed as GMP numbers as arguments.
php
// PHP program for comparing two
// GMP numbers are passed as arguments
// generate GMP numbers using gmp_init()
$num1
= gmp_init (12355);
$num2
= gmp_init (12356);
// compares these two numbers and
// produces the result & quot; -1 & quot; like $num1 < $num2
$res
= gmp_cmp (
$num1
,
$num2
);
echo
$res
;
?>
Output:-1Link:
http : //php.net/manual/en/function.gmp-cmp.php