PHP Operators : Using Comparison Operators
Posted by Daniel at 5:28 pm
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.. ?>
Wow so complicated.. i never study bout those… what is comparison operator for?
wii gamerz’s last blog post..What is the Wii Zapper?