Comparison Operators
This lesson covers the comparison operators and how you can use them in PHP. It also covers a special comparison operator, i.e., the spaceship operator.
We'll cover the following
Basic operators
Comparison operators, as the name suggests, allow you to compare two values. The following table illustrates the different comparison operators in PHP:
Operator | Name | Example |
---|---|---|
== | Equal | a==b |
=== | Identical | a===b |
!= | Not Equal | a!=b |
!== | Not Identical | a!==b |
< | Less than | a<b |
> | Greater than | a>b |
<= | Less than equal to | a<=b |
>= | Greater than equal to | a>=b |
Note: For basic equality testing, the equal operator
==
is used. For more comprehensive checks, use the identical operator===
.
For instance, the ==
operator will return true when an integer 4
is compared with a character '4'
but the ===
will return false. Run the code snippet below to see how this works:
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy