PHP Operators : Using Comparison Operators
To compare php variables to determine whether they are the same or different.. you can use PHP Comparison Operators. See below for a list of examples..
I. Define the Variables
<?php $num1 = 9; $num2 = 9; $num3 = 22; ?>
A. The Less Than Operator
<?php //Returns true if variable in the left side is less than the right.. $res = ($num1 < $num3); //returns true.. ?>
B. The Greater Than Operator
<?php //Returns true if the variable in left side is greater that the right.. $res = ($num3 > $num1); //returns true.. ?>
C. The Less Than or Equal-to Operator
<?php //returns true if variable on left is less than or equal to right.. $res = ($num3 <= $num1); //returns false ?>
D. The Greater Than or Equal-to Operator
<?php //returns true if variable on left is greater than or equal to right.. $res = ($num3 >= $num2); //returns true.. ?>
E. The Equality Operator
<?php //returns true if both variables are equal to each other $res = ($num1 == $num2); //returns true.. ?>
F. The Not Equal-to Operator
<?php //returns true if the variable on left is not equal to right $res = ($num1 != $num2); //returns false.. ?>
G. The Inequality Operator
<?php //returns true if the variable on left is not equal to right.. $res = ($num1 <> $num2); //returns false.. ?>
Tags: PHP, PHP Tutorials


Hi everyone im 






March 3rd, 2009 at 8:36 pm
Wow so complicated.. i never study bout those… what is comparison operator for?
wii gamerz’s last blog post..What is the Wii Zapper?
Reply
March 4th, 2009 at 12:53 am
You could include the double equality operator i.e == which tests for equality and explain about that too.
Reply
Daniel Dumas (79 comments.) Reply:
March 4th, 2009 at 7:08 am
yeah its already in there
Reply
March 13th, 2009 at 4:45 am
Awesome blog! Just discovered it today… I will definitely be back. I’ve been learning MODX CMS and am having to also learn PhP at the same time.
I love the internet and so glad peeps like you create useful sites!
Ciao!
Reply
March 19th, 2009 at 1:08 pm
I great site for newbies on PHP.
The best thing to learn PHP s 2 study hard
Study, practice and research…
Reply
April 7th, 2009 at 12:00 am
I have much respect for programmers. Im a bit of a control freak so i like to do as much myself… with everything. Well, why not program the code for my site – NOT. Well, at least you give me a place to start.
Reply