Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is the gmp_rootrem() method in PHP?

Abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The gmp_rootrem() function in PHP is used to find the nthn^{th} 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 nthn^{th} root.

  • The second element refers to the remainder of the nthn^{th} 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);
?>
The gmp_rootrem() method

Explanation

  • Line 2: We declare and initialize the variable $nthroot1 to store the result of the 2nd2^{nd} root (also known as the square root) of 64.

  • Line 3: We declare and initialize the variable $nthroot2 to store the result of the 5th5^{th} root of 64.

  • Line 6: We print the array stored in $nthroot1.

  • Line 9: We print the array stored in $nthroot2.

RELATED TAGS

php

CONTRIBUTOR

Abhilash
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring