Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
perfectsquare
communitycreator

What is the gmp_perfect_square() function in PHP?

Hammad Nasir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The gmp_perfect_square function is a function in PHP used to check if the argument passed is a perfect square or not.

Syntax


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

Parameters

The function takes in one parameter, num, a GMPGNU Multiple Precision Arithmetic Library object, integer, or numeric string.

Return value

The function returns true if the parameter passed, i.e., num is a perfect square. Otherwise, false is returned.

Code

<?php
$val1 = "36";
var_dump(gmp_perfect_square($val1))."\n";
$val2 = "12325";
var_dump(gmp_perfect_square($val2))."\n";
?>

Output


bool(true)
bool(false)

RELATED TAGS

php
perfectsquare
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring