PHP/MYSQL

Part IV: Revisiting PHP: Spaceship Operator

Image result for spaceship

Image Courtesy: ExtremeTech

The spaceship operator is used for comparing two expressions. It returns -1, 0 or 1 when $a is respectively less than, equal to, or greater than $b. Comparisons are performed according to PHP’s usual type comparison rules.

This is applied when balancing dual terms. What it give back is a minus one (-1), zero (0) or one (1) value(s) when say a variable $pot is either less than or invariably equivalent to say another variable $potter. Balancing of both are done with respect to PHP’s conversant style of balancing terms. Generally, spaceship operator executes 3 supervisions at a period.

As a typical instance:

<?php

echo (12 <=> 11) . PHP_EOL; # outputs: 1

echo (13 <=> 14) . PHP_EOL; # outputs: -1

echo (15 <=> 16) . PHP_EOL; # outputs: -1

?>