PHP | gmp_rootrem() Function (original) (raw)

Last Updated : 11 Jul, 2025

The gmp_rootrem() is a built-in function in PHP which is used to calculate the nth root of a GMP number (GNU Multiple Precision : For large numbers) and returns the integer component of the nth root and its remainder .Syntax :

gmp_rootrem($num,$n)

Parameters : This function accepts two mandatory parameters as shown in the above syntax. They are specified below :

Examples :

Input : num="8"num = "8" num="8"n = 2 Output : Array ( [0] => GMP Object ( [num] => 2 ) [1] => GMP Object ( [num] => 4 ) )

Input : num="9"num = "9" num="9"n = 2 Output : Array ( [0] => GMP Object ( [num] => 3 ) [1] => GMP Object ( [num] => 0 ) )

Return Value : This function returns a two element array , both the elements being GMP numbers.

Below programs will illustrate the use of gmp_rootrem() function in PHP :Program 1 : The below program illustrates the use of the function with GMP number passed as argument.

php `

rootrem=gmprootrem(rootrem = gmp_rootrem(rootrem=gmprootrem(num, $n); //Display the array elements echo print_r($rootrem); ?>

`

Output

Array ( [0] => GMP Object ( [num] => 2 ) [1] => GMP Object ( [num] => 0 ) )

Program 2 : The below program illustrates the use of the function with numeric string passed as argument.

php `

rootrem=gmprootrem(rootrem = gmp_rootrem(rootrem=gmprootrem(num, $n); //Display the array elements echo print_r($rootrem); ?>

`

Output

Array ( [0] => GMP Object ( [num] => 563 ) [1] => GMP Object ( [num] => 471343 )
)

Reference : https://www.php.net/manual/en/function.gmp-rootrem.php