Horje
PHP gmp_perfect_power() Function

The gmp_perfect_power() function is an inbuilt function in PHP that is used to check the perfect power of the number.

Syntax:

gmp_perfect_power(GMP|int|string $num): bool

Parameters: This function accepts only one parameter which is described below.

  • $num: A GMP number resource representing the number you want to check for being a perfect power.

Return Value: The gmp_perfect_power() function returns the true of the perfect power existing of the number otherwise this function will return false.

Program 1: The following program demonstrates the gmp_perfect_power() function.

PHP

<?php
    
$num = 4;
  
if (gmp_perfect_square($num)) {
    echo "This is  perfect square number";
} else {
    echo "This is not perfect square number";
}
?>

Output:

This is  perfect square number 

Program 2: The following program demonstrates the gmp_perfect_power() function.

PHP

<?php
    
$num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  
$array_length = count($num);
  
for ($i = 0; $i < $array_length; $i++) {
    $square = $num[$i] * $num[$i];
    if (gmp_perfect_power($square)) {
        echo "This is perfect square number $square.\n";
    }
}
?>

Output:

This is perfect square number 1.
This is perfect square number 4.
This is perfect square number 9.
This is perfect square number 16.
This is perfect square number 25.
This is perfect square number 36.
This is perfect square number 49.
This is perfect square number 64.
This is perfect square number 81.
This is perfect square number 100.

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




Reffered: https://www.geeksforgeeks.org


PHP

Related
PHP gmp_init() Function PHP gmp_init() Function
PHP gmp_binomial() Function PHP gmp_binomial() Function
PHP sprintf() Function PHP sprintf() Function
PHP vfprintf() Function PHP vfprintf() Function
PHP token_get_all() Function PHP token_get_all() Function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12