|
Free
PHP Tutorials
|
![]() |
home |
Stay
at Home and Learn
|
|||||||
PHP Tutorials |
||||||||
|
Comparison Operators in PHP
You saw in the last section how to test what is inside of a variable. You used if, else if, and else. You used the double equals sign (==) to test whether the variable was the same thing as some direct text. The double equals sign is known as a Comparison Operator. There a few more of these operands to get used. Heres a list. Take a look, and then well see a few examples of how to use them. |
|||||||
| Operand | Example | Meaning | ||||||
| == | $variable1 == $variable2 | Has the same value as |
||||||
| != | $variable1 != $variable2 | Does NOT have the same value as | ||||||
| < | $variable1 < $variable2 | Less Than | ||||||
| > | $variable1 > $variable2 | Greater Than | ||||||
| <= | $variable1 <= $variable2 | Less than or equals to | ||||||
| >= | $variable1 >= $variable2 | Greater than or equals to | ||||||
|
Here's some more information on the above Operands. =
= (Has the same value
as) if ($variable1 == $variable2) { !=
(Does NOT have the same value as) if ($what_user_entered != $username) { The above code says, If what the user entered is NOT the same as the value in the variable called $username then print something out. <
(Less Than) >
(Greater Than) <=
(Less than or equals to) >=
(Greater than or equals to)
In the next few sections, you'll see some examples of how to use the
comparison operators. You've already used the double equals sign, so
we'll start with "Not equal to". <-- Back One Page Move on to the Next Part --> <--Back to the PHP Contents Page View all our Home Study Computer Courses
|
||||||||