The gmp_gcd() is an in built function in PHP which is used to calculate the GCD of 2 GMP numbers (GNU Multiple Precision : For large numbers).
Syntax:
gmp_gcd ( $num1, $num2 )
Parameters: This function accepts two GMP numbers $num1 and $num2 as parameters. This function calculates the GCD of these two numbers.
Return Value: This function returns a positive GMP number which is the GCD of $num1 and $num2.
Examples:
Input : gmp_gcd("12", "21")
Output : 3
Input : gmp_gcd("15", "30")
Output : 15
Explanation: In the above example gmp_gcd() function calculates the greatest common divisor of num1 and num2. The result is always positive even if either of, or both, input operands are negative.
Below programs illustrate the gmp_gcd() function in PHP.
Program 1:
<?php $gcd = gmp_gcd("12", "21"); echo gmp_strval($gcd) . "\n"; ?> |
Output:
3
Program 2:
<?php $gcd = gmp_gcd("15", "30"); echo gmp_strval($gcd) . "\n"; ?> |
Output:
15
Reference:
http://php.net/manual/en/function.gmp-gcd.php
Recommended Posts:
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
- PHP | is_numeric() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

