Sunday, September 22, 2024
Google search engine
HomeLanguagesPHP gmp_perfect_power() Function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments