PHP | gmp_sub() Function (original) (raw)
Last Updated : 11 Jul, 2025
The gmp_sub() is an in-built function in PHP which returns the subtraction of the two GMP numbers.(GNU Multiple Precision: For large numbers)Syntax:
gmp_sub($num1, $num2)
Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters shown in the above syntax. These parameters can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number.Return Value: The function returns the subtraction of two numbers num1andnum1 and num1andnum2. Examples:
Input : num1=5,num1=5 , num1=5,num2=10 Output : -5
Input : num1=7,num1=7 , num1=7,num2=1 Output : 6
Below programs illustrate the gmp_sub() function:Program 1: The program below demonstrates the working of gmp_sub() function when GMP number are passed as arguments.
php `
sub=gmpsub(sub = gmp_sub(sub=gmpsub(num1, $num2); // gmp_strval converts GMP number to string // representation in given base(default 10). echo gmp_strval($sub, 2); ?>`
Output:
-101
Program 2: The program below demonstrates the working of gmp_sub() when numeric string are passed as arguments.
php `
sub=gmpsub(sub = gmp_sub(sub=gmpsub(num1, $num2); echo $sub; ?>`
Output:
6
Reference: https://www.php.net/manual/en/function.gmp-sub.php