Comparison operators in PHP

By: Andi, Stig and Derick  

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 = = =.

Most Viewed Articles (in PHP )

Using Codeigniter for PHP application development

Convert a hex string into a 32-bit IEEE 754 float number in PHP

preg_replace() and preg_replace_callback() in PHP

Installing PHP with nginx-server under windows

PHP file upload (Large Files)

Running different websites on different versions of PHP in Windows 2003 & IIS6 platform


PHP 5.1.4 INSTALLATION on Solaris 9 (Sparc)

Building PHP 5.x with Apache2 on SuSE Professional 9.1/9.2

Installing PHP 5.x with Apache 2.x on HP UX 11i and configuring PHP 5.x with Oracle 9i

Cannot load /usr/local/apache/libexec/ into server:

Setting up PHP in Windows 2003 Server IIS7, and WinXP 64

Function to sort array by elements and count of element in PHP

Function to convert strings to strict booleans in PHP

Malware: global $ob_starting;

Latest Articles (in PHP)

Comment on this tutorial