How does the <=> operator compare values in PHP?

The <=> operator in PHP is known as the spaceship operator and is used for comparing two values. It returns 0 if both values are equal, 1 if the left value is greater, and -1 if the right value is greater. This operator is useful for sorting arrays or comparing values in a concise and readable way.

// Example of using the &lt;=&gt; operator to compare two values
$value1 = 10;
$value2 = 5;

$result = $value1 &lt;=&gt; $value2;

if ($result == 0) {
    echo &quot;Both values are equal&quot;;
} elseif ($result == 1) {
    echo &quot;Value 1 is greater than Value 2&quot;;
} else {
    echo &quot;Value 2 is greater than Value 1&quot;;
}