A Tour of Decision Making Structures in PHP - Comparison Operators (Page 2 of 5 )
The following chart shows some common operators you may use in your programs.
operator comparison ------------------------------------------------ x == y checks if the value of x is equal to the value of y x != y checks if the value of x is not equal to the value of y x < y checks if the value of x is less than the value of y x > y checks if the value of x is greater than the value of y x <= y checks if the value of x is less than or equal to the value of y x >= y checks if the value of x is greater than or equal to the value of y (a) && (b) checks if the value of statement a and statement b evaluate to "true" (a) || (b) checks if the value of statement a or statement b evaluate to "true"
Let's apply that information to some example comparisons. Assuming $x holds the value 5, $y holds 100 and $z holds 500:
($x == $y) && ($x <= $z) (5 == 100) && (5 <= 500) false && true > false ($x * $y) == $z (5 * 100) == 500 500 == 500 > true ($x != $y) || ($y == $z) (5 != 100) || (100 == 500) true || false > true
Be sure that you don't confuse = with ==. = assigns a value to a variable while == compares for equality. This can be a source of great frustration for many new programmers until they become more accustomed to working with them.
Next: IF Statements >>
More Programming Basics Articles More By bluephoenix
Please enable JavaScript to view the comments powered by Disqus. blog comments powered by