I understand how the operator works.
It compresses this:
if ($a > $b) {
return 1;
} else if ($a < b) {
return -1;
} else {
return 0;
}
into this
$a <=> $b
But where and how will I use it?
The only place this is somewhat useful is on the callback of usort
. Except there, to use the returned value I still have to use switch
and that defeats the purpose.
switch ($a <=> $b) {
case -1: //code
case 0: //code
case 1: //code
}
Update: My question is not how to use it or how it works. I am asking where this is useful.