PHP comparison operator

Sep 5, 2020 PHP comparison calculus true bool False

Introduction

I think that comparison operators are often used for judgment. The following is a brief summary.

PHP comparison operator

// TRUE when $ a equals $ b after type reciprocal conversion
$ a == $ b

// TRUE if $ a is equal to and of the same type as $ b
$ a === $ b

// TRUE if $ a is not equal to $ b after type reciprocal conversion
$ a! = $ b

// TRUE if $ a is not equal to $ b after type reciprocal conversion
$ a <> $ b

// TRUE if $ a is not equal to or of the same type as $ b
$ a! == $ b

// TRUE when $ a is less than $ b
$ a <$ b

// TRUE when $ a is more than $ b
$ a> $ b

// TRUE when $ a is less than or equal to $ b
$ a <= $ b

// TRUE when $ a is greater than or equal to $ b
$ a> = $ b

// An integer greater than 0, 0, or less than 0 if $ a is greater than, equal to, or less than $ b, respectively.
// Available in PHP 7 and above
$ a <=> $ b

Quote: PHP: Comparison Operators –Manual

The comparison operators == and === are similar, but I think you can implement them more accurately if you use them properly. If you need to determine the type, use ===.

##in conclusion How was it. Let’s master the comparison operator and implement it accurately.