What is the potential issue with comparing floating-point numbers in PHP?

Comparing floating-point numbers in PHP can be problematic due to the inherent imprecision of floating-point arithmetic. This can lead to unexpected results when comparing two floating-point numbers for equality. To solve this issue, it is recommended to compare floating-point numbers within a certain tolerance range instead of checking for exact equality.

$number1 = 0.1 + 0.2;
$number2 = 0.3;

$epsilon = 0.00001; // Tolerance range

if (abs($number1 - $number2) < $epsilon) {
    echo "Numbers are considered equal within tolerance range.";
} else {
    echo "Numbers are not equal.";
}