Programming Tutorials

Comparison operators in PHP

By: Andi, Stig and Derick in PHP Tutorials on 2008-11-22  

Comparison operators enable you to determine the relationship between two operands.

When both operands are strings, the comparison is performed lexicographically. The comparison results in a Boolean value. For the following comparison operators, automatic type conversions are performed, if necessary.

Operator Name Value
=  = Equal to

Checks for equality between two arguments performing type conversion when necessary:
1 = = "1" results in true
1 = = 1 results in true

!= Not equal to Inverse of = =.
> Greater than

Checks if first operand is greater than second

< Smaller than

Checks if first operand is smaller than second

>= Greater than or equal to

Checks if first operand is greater or equal to second

<= Smaller than or equal to

Checks if first operand is smaller or equal to second

For the following two operators, automatic type conversions are not performed and, therefore, both the types and the values are compared.

Operator Name Value
= = = Identical to

Same as == but the types of the operands have to match. No automatic type conversions are performed:
1 = = = "1" results in false.
1 = = = 1 results in true.

!= = Not identical to The inverse of = = =.





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)