• PHP Video Tutorials

PHP - gmp_gcd() Function



Definition and Usage

The gmp_gcd() function calculates GCD of given numbers.

Description

gmp_gcd() will return greatest common divisor of given numbers. The value returned is positive even if the numbers given are negative.

Syntax

gmp_gcd ( GMP $a , GMP $b ) : GMP

Parameters

Sr.No Parameter & Description
1

a

It can a GMP resource number , a gmp object or a numeric string.

2

b

It can a GMP resource number , a gmp object or a numeric string.

Return Values

PHP gmp_gcd() function returns gcd number which is a positive GMP number.

PHP Version

This function will work from PHP Version greater than 5.0.0.

Example 1

Working of gmp_gcd −

<?php
   $gcd = gmp_gcd("12", "18");	
   echo "The GCD is : ".$gcd;
?>

This will produce following result −

The GCD is : 6

Example 2

Working of gmp_gcd −

<?php
   $gcd = gmp_gcd("120", "180");	
   echo "The GCD is : ".$gcd;	
?>

This will produce following result −

The GCD is : 60
php_function_reference.htm
Advertisements