Asked 7 years ago
6 Jan 2017
Views 1531
rajiv

rajiv posted

What is <=> (the 'Spaceship' Operator) in PHP 7?

PHP 7 had introduced new operator <=> called the Spaceship Operator . so what it does ? what is best use of it ? is it help or increase load of web application ?
Phpworker

Phpworker
answered Nov 30 '-1 00:00

<=> is combination of three operator : < (is gretar than ) , > (is less than ) and == (is equal to than)
so it is three way of Combined Comparison in single expression . its called " Combined Comparison "
Nilesh

Nilesh
answered Nov 30 '-1 00:00

<=> operator work on its return value .

how <=> react
suppose a<=>b than
1. if a and b is equal . it return 0
2. if a is greater than b than it return 1
3. if a is less than b than it return -1
means
a==b , return 0
a>b , return 1
a<b , return -1

in short single expression it check three possibilities . make our code shrink little bit .
why <=> is called 'Spaceship' Operator ? - Rasi  
Jan 6 '17 06:14
its only because its look like space <=> - Mitul Dabhi  
Feb 10 '17 22:20
Post Answer