In the context of finding square numbers in PHP, what alternative approach can be taken to ensure accurate results without relying on sqrt()?

When finding square numbers in PHP, an alternative approach to ensure accurate results without relying on sqrt() is to simply multiply a number by itself. This method eliminates the need for square root calculations and provides a straightforward way to determine if a number is a perfect square.

// Alternative approach to finding square numbers in PHP
function isSquare($num) {
    $root = intval(sqrt($num));
    return ($root * $root == $num);
}

// Test the function
$num = 16;
if (isSquare($num)) {
    echo "$num is a square number.";
} else {
    echo "$num is not a square number.";
}