Computer >> Computer tutorials >  >> Programming >> PHP

gmp_gcd() function in PHP


The gmp_gcd() function computes the GCD of 2 GMP numbers.

Syntax

gmp_gcd (val1, val2)

Parameters

  • val1: The first GMP number.

  • val2: The second GMP number.

Return

The gmp_gcd() function returns the GCD of val1 and val2.

Example

The following is an example to get the GCD of two numbers using the gmp_gcd() function in PHP:

<?php
   $res = gmp_gcd("30", "45");
   echo gmp_strval($res);
?>

Output

The following is the output:

15