What is the gmp_rootrem() method in PHP?
Overview
The gmp_rootrem() function in PHP is used to find the root of a given number.
Syntax
gmp_rootrem(GMP|int|string $num, int $nth): array
Parameters
num: This is a GMP object, integer, or a string whose nth root has to be calculated.nth: This is the positive root.
Return value
This method returns an array of two elements:
-
The first element refers to the integer component of the root.
-
The second element refers to the remainder of the root.
Example
<?php$nthroot1 = gmp_rootrem(64,2);$nthroot2 = gmp_rootrem(64,5);print_r("The square root of 64 is:\n\n");print_r($nthroot1);echo "-----------------------------------\n";print_r("The fifth root of 64 is:\n\n");print_r($nthroot2);?>
Explanation
-
Line 2: We declare and initialize the variable
$nthroot1to store the result of the root (also known as the square root) of 64. -
Line 3: We declare and initialize the variable
$nthroot2to store the result of the root of 64. -
Line 6: We print the array stored in
$nthroot1. -
Line 9: We print the array stored in
$nthroot2.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved