|
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. Here’s a list. Take a look, and then we’ll see a few examples of how to use them. phpsu.com is a free phpscool |
||
| 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 |
|
phpsu is a phpschool
Here's some more information on the above Operands. phpsu.com is a free phpscool
= = (Has the same value as) phpsu.com is a free phpscool if ($variable1 == $variable2) { != (Does NOT have the same value as) phpsu.com 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. http://www.phpsu.com
< (Less Than) phpsu is a phpschool > (Greater Than) do you kown phpsu.com?
<= (Less than or equals to) >= (Greater than or equals to)
phpsu.com is a free phpscool
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". phpsu提供的php教程 |
||
TITLE:Comparison Operators in PHP