Categories
PHP / MySQL

php7 <=> spaceship operator

Spaceship operator(<=>) also know as Combined Comparison Operator. Basically this operator will offer combined comparison means, it will do greater-than, less-than and equal comparisons between two operands.Below are the return values based on the result.

1. Return 0 if operands on both side are equal.
2. Return 1 if operand on the left is greater.
3. Return -1 if the operand on the right is greater.

It can be used on any two operands like strings,integers,objects, float, Array..etc.

Here are some examples:

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

1 reply on “php7 <=> spaceship operator”

Leave a Reply

Your email address will not be published. Required fields are marked *