What is gmp_perfect_power in PHP?
The gmp_perfect_power, a function in PHP, checks if the argument passed is a
Syntax
gmp_perfect_power(GMP|int|string $num): bool
Parameters
The function takes in one parameter: num.
numcan be a numericstring,object, or of the GMP GNU Multiple Precision Arithmetic Library inttype.
Return value
The function returns a boolean value. The function returns true if num is a perfect power. Otherwise, it returns false.
Code
Let’s run the following code to check whether a number is a perfect power or not using gmp_perfect_power() function.
<?php$val1 = gmp_perfect_power('169');if ($val1 == true) {echo "val1 is a Perfect Power";} else {echo "val1 is not a Perfect Power";}?>
Line 2: Assigns the result of checking if the number 169 is a perfect power using the gmp_perfect_power() function to the variable $val1.
Lines 3–7: Starts an if statement to check if the value of $val1 equals true. If yes, then it prints "val1 is a Perfect Power". Otherwise, "val1 is not a Perfect Power".