This function is only available in PHP 7.3.0 or later
<?php
bool gmp_perfect_power ( GMP|int|string $num )
where,
$num = The number to be checked
?>
<?php
function checkifppw01 ( $a01 )
{
if(PHP_VERSION_ID < 70300)
{
echo 'This function is not available to this PHP version!<br><br>';
exit;
}
if (gmp_perfect_power($a01) == TRUE)
{
echo $a01 . ' is a perfect power!<br><br>';
}
else
{
echo $a01 . ' is NOT a perfect power!<br><br>';
}
}
$a01a = [ '0200000', '0200001', '0x10000', '0x1000A', 65536, 65537 ];
foreach($a01a as $a01)
{
checkifppw01($a01);
}
?>
<?php
function checkifppw02 ( $a02 )
{
if(PHP_VERSION_ID < 70300)
{
echo 'This function is not available to this PHP version!<br><br>';
exit;
}
if (gmp_perfect_power($a02) == TRUE)
{
echo $a02 . ' is a perfect power!<br><br>';
}
else
{
echo $a02 . ' is NOT a perfect power!<br><br>';
}
}
$a02a = [ -8, -6, -4, -2, -1, 0, 1, 2, 4, 6, 8,
"7442665456261594668083173595997",
"7442665456261594668083173595998",
PHP_INT_MIN,
PHP_INT_MAX ];
foreach($a02a as $a02)
{
checkifppw02($a02);
}
?>