PHP 8.4.2 Released!

gmp_perfect_square

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

gmp_perfect_squarePerfect square check

Description

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

Check if a number is a perfect square.

Parameters

num

The number being checked as a perfect square.

A GMP object, an int, or a string that can be interpreted as a number following the same logic as if the string was used in gmp_init() with automatic base detection (i.e. when base is equal to 0).

Return Values

Returns true if num is a perfect square, false otherwise.

Examples

Example #1 gmp_perfect_square() example

<?php
// 3 * 3, perfect square
var_dump(gmp_perfect_square("9"));

// not a perfect square
var_dump(gmp_perfect_square("7"));

// 1234567890 * 1234567890, perfect square
var_dump(gmp_perfect_square("1524157875019052100"));
?>

The above example will output:

bool(true)
bool(false)
bool(true)

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top